Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 666 Bytes

sed.md

File metadata and controls

36 lines (29 loc) · 666 Bytes

sed command

  • Replace string in a file
sed 's/<string>/<replaced_string>/' <filename>
  • Replace the nth occurence of a pattern
sed 's/<string>/<replaced_string>/n' <filename>
  • Replace all occurences of the pattern
sed 's/<string>/<replaced_string>/g' <filename>
  • Replace from nth occurence to all occurences:
sed 's/<string>/<replaced_string>/4g' <filename>
  • Delete a particular line from a file (assuming line 3)
sed '3d' <filename>
  • Delete the last line of the file
sed '$d' <filename>
  • Delete a number of lines (assuming from line 5 to 10)
sed '5,10d' <filename>