Guest User

Untitled

a guest
Oct 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. aaaaaa
  2. bbbbbb
  3. !! 1234
  4. !! 4567
  5. ccccc
  6. ddddd
  7. !! 1111
  8.  
  9. first line
  10. second line
  11. third line
  12.  
  13. aaaaaa
  14. bbbbbb
  15. first line
  16. second line
  17. ccccc
  18. ddddd
  19. third line
  20.  
  21. awk '
  22. /^!!/{ #for line stared with `!!`
  23. getline <"file2.txt" #read 1 line from outer file into $0
  24. }
  25. 1 #alias for `print $0`
  26. ' file1.txt
  27.  
  28. awk '
  29. NR == FNR{ #for lines in first file
  30. S[NR] = $0 #put line in array `S` with row number as index
  31. next #starts script from the beginning
  32. }
  33. /^!!/{ #for line stared with `!!`
  34. $0=S[++count] #replace line by corresponded array element
  35. }
  36. 1 #alias for `print $0`
  37. ' file2.txt file1.txt
  38.  
  39. $ perl -pe 'BEGIN{ chomp(@a=`cat file2.txt`) } s/^!!.*/$a[$i++]/e' file1.txt
  40. aaaaaa
  41. bbbbbb
  42. first line
  43. second line
  44. ccccc
  45. ddddd
  46. third line
Add Comment
Please, Sign In to add comment