awk

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

How to find grid points nearest to given location using shell script?

纵饮孤独 提交于 2020-12-06 12:53:06
问题 I have two different files. Part of those files are: file 1: ifile1.txt 21 10.3 70.32 09 32 11.3 71.43 10 33 15.4 75.00 00 54 17.3 68.03 12 95 19.2 65.02 21 99 20.1 80.10 11 and so on...... Where 1st column is the ID, 2nd column refers to x-axis, 3rd column refers to y-axis, 4th column refers to value file2: ifile2.txt 10.10 70.12 10 10.11 73.33 08 11.05 72.40 00 11.30 69.13 15 12.00 64.02 27 12.05 79.20 25 13.10 80.32 10 13.11 75.43 06 14.05 74.00 02 14.20 69.03 15 16.40 65.02 13 16.55 68.10

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.

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

Rounding floating number using AWK

ぃ、小莉子 提交于 2020-11-29 05:01:30
问题 I have a file b.xyz as, -19.794325 -23.350704 -9.552335 -20.313872 -23.948248 -8.924463 -18.810708 -23.571757 -9.494047 -20.048543 -23.660052 -10.478968 I want to limit each of the entries to three decimal digits. I tried this one awk '{ $1=sprintf("%.3f",$1)} {$2=sprintf("%.3f",$2)} {$3=sprintf("%.3f",$3)} {print $1, $2, $3}' b.xyz it works for three columns, but how to expand it to apply for n/all columns? 回答1: If you will always have three fields, then you can use: $ awk '{printf "%.3f %

Rounding floating number using AWK

本小妞迷上赌 提交于 2020-11-29 05:01:27
问题 I have a file b.xyz as, -19.794325 -23.350704 -9.552335 -20.313872 -23.948248 -8.924463 -18.810708 -23.571757 -9.494047 -20.048543 -23.660052 -10.478968 I want to limit each of the entries to three decimal digits. I tried this one awk '{ $1=sprintf("%.3f",$1)} {$2=sprintf("%.3f",$2)} {$3=sprintf("%.3f",$3)} {print $1, $2, $3}' b.xyz it works for three columns, but how to expand it to apply for n/all columns? 回答1: If you will always have three fields, then you can use: $ awk '{printf "%.3f %

Rounding floating number using AWK

丶灬走出姿态 提交于 2020-11-29 05:01:05
问题 I have a file b.xyz as, -19.794325 -23.350704 -9.552335 -20.313872 -23.948248 -8.924463 -18.810708 -23.571757 -9.494047 -20.048543 -23.660052 -10.478968 I want to limit each of the entries to three decimal digits. I tried this one awk '{ $1=sprintf("%.3f",$1)} {$2=sprintf("%.3f",$2)} {$3=sprintf("%.3f",$3)} {print $1, $2, $3}' b.xyz it works for three columns, but how to expand it to apply for n/all columns? 回答1: If you will always have three fields, then you can use: $ awk '{printf "%.3f %

awk - concatenate two string variable and assign to a third

孤街醉人 提交于 2020-11-25 05:53:39
问题 In awk, I have 2 fields: $1 and $2. They are both strings that I want to concatenate and assign to a variable. 回答1: Just use var = var1 var2 and it will automatically concatenate the vars var1 and var2 : awk '{new_var=$1$2; print new_var}' file You can put an space in between with: awk '{new_var=$1" "$2; print new_var}' file Which in fact is the same as using FS , because it defaults to the space: awk '{new_var=$1 FS $2; print new_var}' file Test $ cat file hello how are you i am fine $ awk '