sed examples

Various Linux Stuff
Post Reply
thockman
Site Admin
Posts: 104
Joined: Thu Dec 15, 2005 5:51 pm
Location: Kansas City
Contact:

sed examples

Post by thockman » Mon Jan 12, 2009 11:30 am

The below lines will grep thru the files that are passed to it from a for cmd, find the lines that have session.timeout, exclude Syntax and =%s_, then replace the line with session.timeout=-300000

Code: Select all

nlinerep="`cat ${1} | grep session.timeout= | grep -v Syntax | grep -v =%s_`"
sed "s/$nlinerep/session.timeout=300000/g" $1 > /tmp/$$ && mv /tmp/$$ $1
Here is how I called script
for i in $cat tcffiles.txt); do ./script.sh $i; done

Find pattern in a line and delete the whole line.

Code: Select all

sed -i "/maint.html/d" filename.ext
Append right after pattern match inline.

Code: Select all

sed -i '/matchpattern/s|$|Texttoappend|' filename.ext
Find pattern to delete and the number of lines after. The example will find name and then remove it and the next two lines.

Code: Select all

sed -i '/name/,+2 d' test
echo to sed for variables.

Code: Select all

for i in $(ls *curval*); do nf=`echo $i | sed "s/curval/newval/g"`; mv $i $nf ; done

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests