Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

sed

sed – stream editor

SYNOPSIS

sed [-Ealnru] command [-I extension] [-i extension] [file...]
sed [-Ealnru] [-ecommand] [-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

PATTERN173281t47812473218362131321y748t2148tPATTERN2PATTERN1dhsajdgghqwdbhjdshajdgsahdjashjdhdghjsagdhjashgshjdagdhjdhsajdhasjPATTERN2===============PATTERN1236713372183671362163721PATTERN2
cat file.txt | sed "/^ *$/d"

Output

PATTERN173281t47812473218362131321y748t2148tPATTERN2PATTERN1dhsajdgghqwdbhjdshajdgsahdjashjdhdghjsagdhjashgshjdagdhjdhsajdhasjPATTERN2===============PATTERN1236713372183671362163721PATTERN2

old solution

find . -name "*.txt"|whileread txtfile;do sed -i "" -e "s/ : /:/g"${txtfile};done
Screenshot 2024-11-03 at 8 12 36 p m

About

BASH

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors