sed Command
Removing Characters using sed command
REMOVING $ (DOLLAR) FROM A FILE USING SED
sed -e 's/[$]//g' FE.txt
> Final.txt
Where FE.txt is
the source file and Final.txt will be the file after removing dollar
REMOVING DOUBLE QUOTES “
sed -e 's/"//g' FE.txt
> Final.txt
Where FE.txt is the source file and Final.txt will be
the file after removing quotes
REMOVING SINGLE
QUOTES ‘
sed -e "s/'//g"
FE.txt > Final.txt
Where FE.txt is the source file and Final.txt will be
the file after removing quotes
REMOVING COLON :
sed -e 's/://g' FE.txt > Final.txt
Where FE.txt is the source file and Final.txt will be
the file after removing colon
REMOVING SEMI-COLON;
sed -e 's/;//g' FE.txt > Final.txt
Where FE.txt is the source file and Final.txt will be
the file after removing semi colon
REMOVING SPACES
sed -e 's/ //g' FE.txt >
Final.txt
Where FE.txt is the source file and Final.txt will be
the file after removing spaces
TO GET THE LINES BETWEEN
STRINGS
sed -n '/START/,/END/p'
test.txt > test1.txt
This will get
the lines between START and END and including these.
TO DELETE THE LINES WHICH
CONTAINS A PARTICULAR STRING
sed '/04546986/d' filename1.txt
> filename2.txt
This will delete the line containing 04546986 in file
filename1.txt and prints it to filename2.txt
TO REPLACE A STRING WITH
ANOTHER STRING
sed -e 's/YYY/XYZ/g' filename1.txt
> filename2.txt
This will
replace YYY with XYZ in file filename1.txt and prints it to filename2.txt
To replace \n (not new Line)
sed -e 's/\\n//g' siva.txt
> filename2.txt
Put escape
character to remove character \n
Replace if in the same line.
sed 's/good/bad/2' abbb.txt
> out.txt
Replace if different Line:
- First replace all new lines with ';'
- Then apply sed.
- Then Replace ';' with new lines.
tr '\n' ';' < inp.txt > temp1.txt
sed 's/good/bad/5' temp1.txt > temp2.txt
tr ';' '/n' < temp2.txt > out.txt
No comments:
Post a Comment