sed – stream editor
sed [-Ealnru] command [-I extension] [-i extension] [file...]
sed [-Ealnru] [-ecommand] [-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.txtThe 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.txtcat sample.txtConsole 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' FILEcat file.txt
PATTERN173281t47812473218362131321y748t2148tPATTERN2PATTERN1dhsajdgghqwdbhjdshajdgsahdjashjdhdghjsagdhjashgshjdagdhjdhsajdhasjPATTERN2===============PATTERN1236713372183671362163721PATTERN2cat file.txt | sed "/^ *$/d"Output
PATTERN173281t47812473218362131321y748t2148tPATTERN2PATTERN1dhsajdgghqwdbhjdshajdgsahdjashjdhdghjsagdhjashgshjdagdhjdhsajdhasjPATTERN2===============PATTERN1236713372183671362163721PATTERN2find . -name "*.txt"|whileread txtfile;do sed -i "" -e "s/ : /:/g"${txtfile};done