Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- aaaaaa
- bbbbbb
- !! 1234
- !! 4567
- ccccc
- ddddd
- !! 1111
- first line
- second line
- third line
- aaaaaa
- bbbbbb
- first line
- second line
- ccccc
- ddddd
- third line
- awk '
- /^!!/{ #for line stared with `!!`
- getline <"file2.txt" #read 1 line from outer file into $0
- }
- 1 #alias for `print $0`
- ' file1.txt
- 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
- }
- /^!!/{ #for line stared with `!!`
- $0=S[++count] #replace line by corresponded array element
- }
- 1 #alias for `print $0`
- ' file2.txt file1.txt
- $ perl -pe 'BEGIN{ chomp(@a=`cat file2.txt`) } s/^!!.*/$a[$i++]/e' file1.txt
- aaaaaa
- bbbbbb
- first line
- second line
- ccccc
- ddddd
- third line
Add Comment
Please, Sign In to add comment