Skip to content

c4arl0s/sed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sed

sed – stream editor

SYNOPSIS

sed [-Ealnru] command [-I extension] [-i extension] [file ...]
sed [-Ealnru] [-e command] [-f command_file] [-I extension] [-i extension] [file ...]

EXAMPLES

  • 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

Replace with sed

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!

scape slash character to find a path

Replace / with / to scape slash character

echo "/path/to/some/where/" | sed -e "s=/=\\\/=g"

output

\/path\/to\/some\/where\/

Find a string block between two patterns

sed -n '/PAT1/,/PAT2/p' FILE

Remove empty lines in a 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published