CSx
Github Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

đŸ’ģ Sed


Wrap every line output in quotes

  • sed 's/"\(.*\)/"\1"/g'

Remove Whitespace Lines

  • sed '/^$/d'

Remove everything before match

  • sed 's/.*match//'

Remove everything after match

  • sed 's/match.*//g'

Replace first instance of match

  • sed '0,/example1/{s/example1/example2/}'

Replace Nth instance of match

  • sed 's/example1/example2/2g

    2g == 2nd match

  • sed -n '7p'

    7th line

  • sed '7!d'

    Also 7th line

Replace newline chracter w/space

  • Tip: Easier with tr

    • tr '"\n' ' ' < input_filename

Remove brackets and everything inside brackets

  • sed -e 's/\[[^][]*\]//g'

Add line numbers to the beginning of each line

  • s/^/\=line('.').". "

    • 🔗Vim: %s/^/\=line('.').". "

Resources