文件 1:
19a9s
c9019
5777
文件 2:
99a9s
89019
10919
预期产出
19a9s
89019
5777
因此,file 1
它line#2
以 letter 开头c
。如果该行以字母开头,我想将它用作条件,c
所以我想从第二个文件替换它file 2
我尝试了以下但未能给我预期的输出:
awk '
NR == FNR{ #for lines in first file
S[NR] = $0 #put line in array `S` with row number as index
next #starts script from the beginning
}
/^c/{$0=S[FNR]}{ #for line stared with `c`
$0=S[++count] #replace line by corresponded array element
}
1 #alias for `print $0`
' file2 file1
多远会
明白?