Differences between revisions 2 and 3
Revision 2 as of 2023-02-22 09:29:20
Size: 618
Editor: SamatJain
Comment: tr
Revision 3 as of 2023-02-22 09:30:03
Size: 617
Editor: SamatJain
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= sed and tr == = sed and tr =

sed and tr

Options

  • -i makes an edit in-place. -i.bak will make an edit in-place, but create a backup file w/ suffix .bak

Quick reference

Replace text in all files in & under the current directory

find . -type f -exec sed -i 's/old/new/g' {} \;

tr

Because sed works upon newlines, it makes it difficult to actually process newlines. Use tr instead.

# Remove all newlines
tr -d '\n'

# Replace space w/ newlines
tr -s '[[:space:]]' '\n'

# Replace newlines w/ space
tr '\n' ' '

SamatsWiki: CheatSheet/Sed (last edited 2023-02-22 09:30:03 by SamatJain)