sed

How to extract email headers extending on multiple lines from file

江枫思渺然 提交于 2020-12-06 20:23:03
问题 I am trying to extract the To header from an email file using sed on linux. The problem is that the To header could be on multiple lines. e.g: To: name1@mydomain.org, name2@mydomain.org, name3@mydomain.org, name4@mydomain.org, name5@mydomain.org Message-ID: <46608700.369886.1549009227948@domain.org> I tried the following: sed -n -e '/^[Tt]o: / { N; p; }' _message_file_ | awk '{$1=$1;printf("%s ",$0)};NR%2==0{print ""}' The sed command extracts the line starting with To and next line. I pipe

AWK or sed way to paste non-adjacent lines

雨燕双飞 提交于 2020-12-06 06:36:49
问题 $ cat file aaa bbb ccc ddd eee jjj kkk lll mmm nnn ooo ppp The following AWK command will paste the 'mmm' line at the end of the 'ddd eee' line. Is there a simpler way to do this using AWK or sed? $ awk 'FNR==NR {if (NR==4) foo=$0; next} FNR==2 {print $0" "foo; next} FNR==4 {next} 1' file file aaa bbb ccc ddd eee mmm jjj kkk lll nnn ooo ppp To clarify: I want to paste line 4 at the end of line 2 in this particular file, with a single space between the 'ddd eee' and the 'mmm'. That's the task.

AWK or sed way to paste non-adjacent lines

泪湿孤枕 提交于 2020-12-06 06:36:48
问题 $ cat file aaa bbb ccc ddd eee jjj kkk lll mmm nnn ooo ppp The following AWK command will paste the 'mmm' line at the end of the 'ddd eee' line. Is there a simpler way to do this using AWK or sed? $ awk 'FNR==NR {if (NR==4) foo=$0; next} FNR==2 {print $0" "foo; next} FNR==4 {next} 1' file file aaa bbb ccc ddd eee mmm jjj kkk lll nnn ooo ppp To clarify: I want to paste line 4 at the end of line 2 in this particular file, with a single space between the 'ddd eee' and the 'mmm'. That's the task.

AWK or sed way to paste non-adjacent lines

前提是你 提交于 2020-12-06 06:35:25
问题 $ cat file aaa bbb ccc ddd eee jjj kkk lll mmm nnn ooo ppp The following AWK command will paste the 'mmm' line at the end of the 'ddd eee' line. Is there a simpler way to do this using AWK or sed? $ awk 'FNR==NR {if (NR==4) foo=$0; next} FNR==2 {print $0" "foo; next} FNR==4 {next} 1' file file aaa bbb ccc ddd eee mmm jjj kkk lll nnn ooo ppp To clarify: I want to paste line 4 at the end of line 2 in this particular file, with a single space between the 'ddd eee' and the 'mmm'. That's the task.

removing multibyte characters from a file using sed

帅比萌擦擦* 提交于 2020-12-05 07:46:11
问题 i need to remove all multibyte characters from a file, i dont know what they are so i need to cover the whole range. I can find them using grep like so: grep -P "[\x80-\xFF]" 'myfile' Trying to do a simular thing with sed, but delete them instead. Cheers 回答1: Give this a try: LANG=C sed 's/[\x80-\xFF]//g' filename 回答2: you can use iconv to convert from one encoding to another 来源: https://stackoverflow.com/questions/3521106/removing-multibyte-characters-from-a-file-using-sed

removing multibyte characters from a file using sed

风格不统一 提交于 2020-12-05 07:46:04
问题 i need to remove all multibyte characters from a file, i dont know what they are so i need to cover the whole range. I can find them using grep like so: grep -P "[\x80-\xFF]" 'myfile' Trying to do a simular thing with sed, but delete them instead. Cheers 回答1: Give this a try: LANG=C sed 's/[\x80-\xFF]//g' filename 回答2: you can use iconv to convert from one encoding to another 来源: https://stackoverflow.com/questions/3521106/removing-multibyte-characters-from-a-file-using-sed

Modify the content of variable using sed (or something similar)

∥☆過路亽.° 提交于 2020-12-05 05:07:09
问题 I wrote a BASH file that features multiple embedded loops of the form for P in {'0.10','0.20', [...] '0.90','1.00'}; do for Q in {'0.10','0.20', [...] ,'0.90','1.00'}; do [...] I use these variables both as parameters for a command line application, and to create file names directly in BASH. I would like to create duplicates, say $P_REP=0_10 that replaces the dot by an underscore without writting a explicit switch statement for every case, or some hardcoded equivalent. The (non-elegant way) I

Remove long prefix only from a specific field in all the lines of a file?

萝らか妹 提交于 2020-11-30 00:15:08
问题 I have a file containing the following lines (3 fields delimited by space): component1 /dev/user/test 12344 component2 master abcefa123 component3 trunk 72812 component4 /branch/user/integration bc89fa component5 trunk 989091 component6 integration/test bc7829ac component7 /branch/dev/user/various eded34512 I need to manipulate the field 2 to cut its long prefix (same as you do in bash with ${string##*}) and to get the following result: component1 test 12344 component2 master abcefa123

Use sed to edit crontab

匆匆过客 提交于 2020-11-29 08:31:36
问题 I am writing a sed command that should uncomment an entry in crontab. Is there a better way to do this? The first option that comes to mind is sed. Example: crontab -l # 5 * * * 3 bash test.sh The sed command should uncomment this entry. This is what I have now. sed "s#\# 5 * * * 3 bash test.sh#5 * * * 3 bash test.sh#" Obviously this sed command doesn't do the task. ps:the sed command will eventually make its way into a script. 回答1: Sed is great for matching specific regular expressions and

Use sed to edit crontab

♀尐吖头ヾ 提交于 2020-11-29 08:31:08
问题 I am writing a sed command that should uncomment an entry in crontab. Is there a better way to do this? The first option that comes to mind is sed. Example: crontab -l # 5 * * * 3 bash test.sh The sed command should uncomment this entry. This is what I have now. sed "s#\# 5 * * * 3 bash test.sh#5 * * * 3 bash test.sh#" Obviously this sed command doesn't do the task. ps:the sed command will eventually make its way into a script. 回答1: Sed is great for matching specific regular expressions and