Guest User

Untitled

a guest
Feb 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. Stuff
  2.  
  3. Pattern
  4.  
  5. Stuff
  6.  
  7. patternline=$(grep -n "Pattern" "/my/file" | cut -f1 -d:)
  8. firstcut=$(($patternline -1))
  9.  
  10. firstpart=$(sed -n 1,"$firstcut"p "/my/file")
  11. secondpart=$(sed -n ''"$abspathcomment"',$p' "/my/file")
  12.  
  13. # Indentation intentional as snippet is nested within an IF statement
  14. text=$(cat <<EOF
  15.  
  16. Text I want to insert with one leading and two trailing new lines
  17.  
  18.  
  19. EOF
  20. )
  21.  
  22. echo "$firstpart$text$secondpart" > "/my/file"
  23.  
  24. Stuff
  25.  
  26. Text I want to insert with one leading and two trailing new lines
  27.  
  28.  
  29. Pattern
  30.  
  31. Stuff
  32.  
  33. Stuff
  34.  
  35. Text I want to insert with one leading and two trailing new linesPattern
  36.  
  37. Stuff
Add Comment
Please, Sign In to add comment