sed
– stream editor
sed [-Ealnru] command [-I extension] [-i extension] [file ...]
sed [-Ealnru] [-e command] [-f command_file] [-I extension] [-i extension] [file ...]
- Replace
‘bar’
with‘baz’
when piped from another command:
echo "An alternate word, like bar, is sometimes used in examples." | sed 's/bar/baz/'
- Using backlashes can sometimes be hard to read and follow:
echo "/home/example" | sed 's/\/home\/example/\/usr\/local\/example/'
- Using a different separator can be handy when working with paths:
echo "/home/example" | sed 's#/home/example#/usr/local/example#'
- Replace all occurances of ‘foo’ with ‘bar’ in the file test.txt, without creating a backup of the file:
sed -i '' -e 's/foo/bar/g' test.txt
The list below gives you the 1000 most frequently used English words in alphabetical order. Once you've mastered the shorter vocabulary lists, this is the next step. It would take time to learn the entire list from scratch, but you are probably already familiar with some of these words. Feel free to copy this list into your online flashcard management tool, an app, or print it out to make paper flashcards. You'll have to look up the definitions on your own either in English or in your own language. Good luck improving your English vocabulary!
How to find and substitute 1000 with 9999 using sed on MacOS
sed -e "s/1000/9999/" -i "" sample.txt
cat sample.txt
Console output
The list below gives you the 9999 most frequently used English words in alphabetical order. Once you've mastered the shorter vocabulary lists, this is the next step. It would take time to learn the entire list from scratch, but you are probably already familiar with some of these words. Feel free to copy this list into your online flashcard management tool, an app, or print it out to make paper flashcards. You'll have to look up the definitions on your own either in English or in your own language. Good luck improving your English vocabulary!
Replace / with / to scape slash character
echo "/path/to/some/where/" | sed -e "s=/=\\\/=g"
output
\/path\/to\/some\/where\/
sed -n '/PAT1/,/PAT2/p' FILE
cat file.txt
PATTERN1
73281t478124
73218362131
321y748t2148t
PATTERN2
PATTERN1
dhsajdgghqwdbhj
dshajdgsahdjashjd
hdghjsagdhjas
hgshjdagdhj
dhsajdhasj
PATTERN2
===============
PATTERN1
236713
372183671
362163721
PATTERN2
cat file.txt | sed "/^ *$/d"
Output
PATTERN1
73281t478124
73218362131
321y748t2148t
PATTERN2
PATTERN1
dhsajdgghqwdbhj
dshajdgsahdjashjd
hdghjsagdhjas
hgshjdagdhj
dhsajdhasj
PATTERN2
===============
PATTERN1
236713
372183671
362163721
PATTERN2