sed examples
Posted: 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
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.
Append right after pattern match inline.
Find pattern to delete and the number of lines after. The example will find name and then remove it and the next two lines.
echo to sed for variables.
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
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
Code: Select all
sed -i '/matchpattern/s|$|Texttoappend|' filename.ext
Code: Select all
sed -i '/name/,+2 d' test
Code: Select all
for i in $(ls *curval*); do nf=`echo $i | sed "s/curval/newval/g"`; mv $i $nf ; done