1 => To delete
any line from any file with sed example.
A: Below command
will search and delete httpd line from /etc/rc.local
#sed
-i '/httpd/d' /etc/rc.local
B: To make entry in
side file with sed example
#sed
-i '$ i\\/opt\/lampp\/tomcat\/bin\/startup.sh' /etc/rc.local
#sed
-i '$ i\emrepair' /etc/rc.local
Note : Above command
will make entry before last line where $i is used for indicate last
line
C: This command will
make entry in 3rd line of any file.
#sed
-i ' 3i repair' /etc/rc.local
D: Below command
will search line and make entry after that
#sed
-i '/memory_limit/ a\memory_limit = 1024' /etc/php.ini
E: Below command
will search and replace word .
#sed
-i 's/FSCKFIX=no/FSCKFIX=yes/' /etc/default/rcS
F: Below command
will put # before all the line in a file
#sed
-i s/^/#/ filename
G: Remove the 3rd
line:
#sed '3d' fileName.txt
H: Remove the line containing the string "awk":
#sed '/awk/d' filename.txt
I: Remove the last line:
#sed '$d' filename.txt
J: Remove all empty lines:
#sed '/^$/d' filename.txt #sed '/./!d' filename.txt
K: Remove the line matching by a regular
expression (by eliminating one containing digital
characters, at least 1 digit, located at
the end of the line):
#sed '/[0-9/][0-9]*$/d' filename.txt
L: Remove the interval between lines 7 and 9:
#sed '7,9d' filename.txt
M: The same operation as above but replacing the address with
parameters:
#sed '/-Start/,/-End/d' filename.txt
N: The above examples are only changed at the display of the file
(stdout1= screen).
For permanent changes to the old versions (<4) use a temporary file for GNU sed using the
For permanent changes to the old versions (<4) use a temporary file for GNU sed using the
"-i[suffix]":
#sed -i".bak" '3d' filename.txt
N: Search 24 character alfa numeric value in file and replace it
#sed 's/[[:alnum:]]\{24\}/Nirmal/g' filename.txt
No comments:
Post a Comment