Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. claudio
  2. antonio
  3. claudio
  4. michele
  5.  
  6. claudia
  7. antonio
  8. claudio
  9. michele
  10.  
  11. sed -e '1,/claudio/s/claudio/claudia/' nomi
  12.  
  13. sed -e '0,/claudio/ s/claudio/claudia/' nomi
  14.  
  15. awk
  16.  
  17. $ awk 'NR==1,/claudio/{sub(/claudio/, "claudia")} 1' nomi
  18. claudia
  19. antonio
  20. claudio
  21. michele
  22.  
  23. sed -n ':a;N;$bb;ba;:b;s/(claudi)o/1a/;p' file
  24. sed -n '1h;1!H;${g;s/(claudi)o/1a/;p;}' file
  25.  
  26. sed -n ' # don't implicitly print input
  27. :a # label "a"
  28. N # append next line to pattern space
  29. $bb # at the last line, goto "b"
  30. ba # goto "a"
  31. :b # label "b"
  32. s/(claudi)o/1a/ # replace
  33. p # and print
  34. ' file
  35.  
  36. sed -n ' # don't implicitly print input
  37. 1h # put line 1 in the hold space
  38. 1!H # for subsequent lines, append to hold space
  39. ${ # on the last line
  40. g # put the hold space in pattern space
  41. s/(claudi)o/1a/ # replace
  42. p # print
  43. }
  44. ' file
  45.  
  46. $ awk '!f && /claudio/ {$0="claudia"; f=1}1' file
  47. claudia
  48. antonio
  49. claudio
  50. michele
  51.  
  52. sed '$H;x;1,/claudio/s/claudio/claudia/;1d' <<IN
  53. claudio
  54. antonio
  55. claudio
  56. michele
  57. IN
  58.  
  59. claudia
  60. antonio
  61. claudio
  62. michele
  63.  
  64. sed --in-place=*.bak -e "1 h;1! H;$! d;$ {g;s/claudio/claudia/;}" -- nomi
  65.  
  66. export chngFrom=claudio
  67. export chngTo=claudia
  68. sed --in-place=*.bak -e "1 h;1! H;$! d;$ {g;s/${chngFrom}/${chngTo}/;}" -- nomi
  69.  
  70. sed -n '/claudio/{s/o/a/;bx};p;b;:x;p;n;bx' nomi
  71.  
  72. sed -n ' # do not print lines by default
  73. /claudio/ { # on lines that match "claudio" do ...
  74. s/o/a/ # replace "o" with "a"
  75. bx # goto label x
  76. } # end of do block
  77. p # print the pattern space
  78. b # go to the end of the script, continue with next line
  79. :x # the label x for goto commands
  80. p # print the pattern space
  81. n # load the next line in the pattern space (clearing old contents)
  82. bx # goto the label x
  83. ' nomi
  84.  
  85. sed -n '/claudia/{p;Q}'
  86.  
  87. sed -n ' # don't print input
  88. /claudia/ # regex search
  89. { # when match is found do
  90. p; # print line
  91. Q # quit sed, don't print last buffered line
  92. { # end do block
  93.  
  94. sed '/(claudi)o/!b;//s//1a/;:1;n;b1'
  95.  
  96. sed '
  97. /(claudi)o/!b # Match the regex `claudio`. But in two parts `claudi` and `o`
  98. # and, for lines that do not match yet go to end (print).
  99. //s//1a/ # For one line that match the previous regex, change o to a.
  100. :1 # label to loop from now on.
  101. n # read next line (it gets auto printed).
  102. b1 # keep (only) printing to the end of file.
  103. '
  104.  
  105. echo 'claudio
  106. antonio
  107. claudio
  108. michele' | sed -z 's/claudio/claudia/'
  109.  
  110. claudia
  111. antonio
  112. claudio
  113. michele
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement