Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modify just one field on one line in many files !!!

Status
Not open for further replies.

octar

Technical User
Oct 21, 2002
28
AU
Hi,

I have recently created around 100 printers and need to modify one field in one line of each of the hundred configuration files:

FILE: /var/spool/lpd/pio/@local/custom/prt001:hp@p001
FILE: /var/spool/lpd/pio/@local/custom/prt002:hp@p002
:
:
FILE: /var/spool/lpd/pio/@local/custom/prt101:hp@p101

The field are as follows, I need to change the + to a ! at the end of the line.

prt001:MN@p001::614:_Z:Dn%IWY:+
to
prt001:MN@p001::614:_Z:Dn%IWY:!

The problem is that this is only one line of many in each configuration file.

Can anyone help??


I'm fine with getting each file as follows:

for i in `ls /var/spool/lpd/pio/@local/custom`
do
echo "This is the current file $i"
done

thanks in advance
 
Try this :
for i in `ls /var/spool/lpd/pio/@local/custom`
do
echo "This is the current file $i"
sed 's/\+$/\!/g' $i > $i.new
mv $i.new $i
done


HTH ((;-)))
Dickie Bird
Honi soit qui mal y pense
 
That is nearrly got it, however... there is more then just one instance of + in the file, so this code changes all the + to ! which unfortunatly I don't want.
I'm thinking of doing a nested loop eg.

for i in printer files
for j in cat each printer file
when the line starts with ":614:_Z" change
:614:_Z:Dn%IWY:+
to
:614:_Z:Dn%IWY:!

does this make sense or is there an easier way?

thanks
 
I can think of one way - others will do it better :

for i in `ls /var/spool/lpd/pio/@local/custom`
do
echo "This is the current file $i"
sed 's/:614:_Z.*+/&!/g' $i > $i.new
sed 's/+!/!/g' $i.new > $i
rm $i.new
done

First find lines beginning :614:_Z & recreate line with a ! at end
Then look for +! and replace with just a '!'

HTH ((;-))) Dickie Bird
Honi soit qui mal y pense
 
Perfect, thanks for your help Dickie Bird
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top