Skip to content

Instantly share code, notes, and snippets.

@shaskumar
Created May 9, 2020 17:41
Show Gist options
  • Save shaskumar/763ac859742ca00d9654505f3f198fd2 to your computer and use it in GitHub Desktop.
Save shaskumar/763ac859742ca00d9654505f3f198fd2 to your computer and use it in GitHub Desktop.
SED linux command
sed 's/t/T' filename - substitute all small t's that are starting letter of any word with capital T's
sed -i 's/t/T' filename - change content of file itself (-i inline)
sed 's/t/T/g' filename - all small t's with capital T's.sed 's/t/T/Ig' filename, ignone case
sed 's/^t/T/g' filename - change only that t with which line starts.
sed 's/t$/T/g' filename - change only last letter t.
sed 's/[0–9]/*/g' filename - change all number from 0 to 9 to *. sed 's/[^0–9]/*/g'. everything but numbers.
sed 's/[a–z]/*/g' filename - change all letter from a to z to *
sed 's/[A–Z]/*/g' filename - change all letter from A to Z to *
sed 's/[a–z][A-Z]/*/g' filename - change letter with small a to z followed by capital A to z to *. eg: thaT to th* (aT changed to *)
sed 's/[a-zA–Z]/*/g' filename - change all letter from A to Z or a to z to *. eg thaT to ****.
[a-Z] won't work as ASCII says capital letter first and then small letters so [A-z] works.
sed 's/[0–9]/(&)/g' filename - change all numbers from 0 to 9 into number itself surrounded by small braces. && with concat same number two times.
T/wo -> T**o: sed 's/\/w/**/g'. so we can put anything for actual command backslash. like sed 's_/w_**_g' will work. anything inplace of _ will also work.
T\/wo ->T**o: sed 's/\\\/w/**g'
/usr/local/share/ -> 0 : sed 's_/usr/local/share_0_g'
sed 's/[0–9]/(&)/g;s/[a-z]/*/g' - two action at once in order.
remove first word - sed 's/\w*.//g'- remove first word(\w*) from line and trim(.) space generated.
remove last word - sed 's/\w*$//g'.
using sed file: sedfile contains 
ss/t/T/g';
s/e/E/g';
run - sed -f sedfile filename.
remove line where word matches - sed 's/matchword/d' filename. add ID to ignore case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment