this script helps to make a sed operation (like search and replace) for only very certain lines in a file. let's say we have a data file (project.dat) and an index file (project.idx) with the line numbers, which we are interested to be changed. for the replacing all 'C' to 'L' we can do the following
#!/bin/sh
#make script for sed
sed 's|$|s/C/L/|' project.idx > project.scr
#or with awk
#awk '{print $1 "s/C/L/"}' project.idx > project.scr
#run sed with -f
sed -f project.scr project.dat > project.new.dat
#remove the script
rm -f project.scr
exit 0
source:
http://www.unix.com/
No comments:
Post a Comment