⇤ ← Revision 1 as of 2021-04-16 05:46:33
Size: 309
Comment:
|
Size: 618
Comment: tr
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
= sed and tr == |
|
Line 12: | Line 14: |
== tr == Because sed works upon newlines, it makes it difficult to actually process newlines. Use tr instead. {{{#!highlight sh numbers=off # Remove all newlines tr -d '\n' # Replace space w/ newlines tr -s '[[:space:]]' '\n' # Replace newlines w/ space tr '\n' ' ' }}} |
= 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' ' '