我有一個小問題awk
,我無法找到解決方案。awk讀取一行的條件,打印另一行的輸出
我想在語法中交換NR ==,所以我讀取NR == 4和輸出NR == 3的條件。
awk -F 'NR ==4 { if ($1 < $2 && NF ==4) print $2 "," $4;
if ($1 < $2 && NF ==3) print $2 "," "--";
if ($1 > $2 && NF ==4) print $1 "," $3;
if ($1 > $2 && NF ==3) print $1 "," "--";
}' infile > outfile
我想是上述(讀取NR == 4,但輸出NR == 3)
awk -F 'NR ==4 { if ($1 < $2 && NF ==4) NR ==3 print $2 "," $4;
NR ==4 if ($1 < $2 && NF ==3) NR ==3 print $2 "," "--";
NR ==4 if ($1 > $2 && NF ==4) NR ==3 print $1 "," $3;
NR ==4 if ($1 > $2 && NF ==3) NR ==3 print $1 "," "--";
}' infile > outfile
infile中:
05:45,11:55,17:37,09:59
0.2,2.3,0.4,2.6
06:18,12:28,18:15
2.3,2.2,0.6
此條件,其中NR期望OUTFILE == 4 $ 1> $ 2 & & NF == 3:
12:28, --:--
當然我會編輯帖子。 Ta –