Operating System - HP-UX
1832306 Members
1965 Online
110041 Solutions
New Discussion

replace multiple strings in fstab

 
Kapil Jha
Honored Contributor

replace multiple strings in fstab

Hello Gurus,
I am very bad in scripting and I need to change 50 entries in a file from lets say
pqr23 to pqr23/abc
pqr24 to pqr24/abc
-----
pqr78 to pqr78/abc

how can we do it....
BR,
Kapil+
I am in this small bowl, I wane see the real world......
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: replace multiple strings in fstab

Shalom

cp /etc/fstab /tmp/fstab
# make a backup
vi /tmp/fstab

:%s/pqr78/"pqr78/abc"/g

Repeat for other changes.

Also sed can be used this way.

http://nl.ijs.si/gnusl/tex/tunix/tips/node220.html

http://student.northpark.edu/pemente/sed/sed1line.txt

http://forums.digitalpoint.com/showthread.php?t=24956

http://lowfatlinux.com/linux-sed.html

A few low fat examples.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Kapil Jha
Honored Contributor

Re: replace multiple strings in fstab

I do not want to do it for everychange there are more than 60 entries would be lot of manpower.
Is there anyway I can do it in one shot.
BR,
Kapil+
I am in this small bowl, I wane see the real world......
Kapil Jha
Honored Contributor

Re: replace multiple strings in fstab

Hey I have done most of the thing....i changes line after to the required thing ;)
like pqr23 abncjfh
so I canged
abncjfh to /abc abncjfh

bad idea but it worked.

I have one more question I need to add a word mns in line number from 31 to 35.

How can we do that.

BR,
Kapil+
I am in this small bowl, I wane see the real world......
V. Nyga
Honored Contributor

Re: replace multiple strings in fstab

Hi,

I don't know how you want to add it (at the beginning/at the end/as a new line?)
and my scripting experience is still at the beginning, but I think 'awk' would do what you want.
Check 'man awk' and search for examples here.
I've an example for sorting a file except the first 2 lines:
cat |awk '{if (NR<=2) {print $0} else {print $0|"sort"}}' >

For your changing I would have used 'sed'
It's like:
sed 's/string1/string2/g' /etc/fstab > /etc/fstab.out
For the additional '/' in your string2 I believe there's something like '\/', but this you would have to search too.

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Kapil Jha
Honored Contributor

Re: replace multiple strings in fstab

Thanks i did it
command is
12,15s/$/abc
will append abc at end of file.
Thans for the help,

BR,
Kapil+
I am in this small bowl, I wane see the real world......