Operating System - HP-UX
1834272 Members
71360 Online
110066 Solutions
New Discussion

Simple question for sed/awk/perl experts

 
SOLVED
Go to solution
Yogeeraj_1
Honored Contributor

Simple question for sed/awk/perl experts

Hello,

I am not a very good script programmer :(

Please help!

The following file should be modified:

...
/backup01/pfs/sy/frm/sy001oc0.fmb
/backup01/pfs/sy/frm/rf910oc0.fmb
/backup01/pfs/sy/frm/rf920oc0.fmb
/backup01/pfs/sy/frm/rf930oc0.fmb
/backup01/pfs/sy/frm/rf940oc0.fmb
/backup01/pfs/sy/frm/rf950oc0.fmb
/backup01/pfs/sy/frm/rf001oc0.fmb
/backup01/pfs/sy/frm/rf810oc0.fmb
...

to become:

...
f60gen /backup01/pfs/sy/frm/sy001oc0.fmb ops\$yd/yd@pfs Compile_All=YES
f60gen /backup01/pfs/sy/frm/rf910oc0.fmb ops\$yd/yd@pfs Compile_All=YES
f60gen /backup01/pfs/sy/frm/rf920oc0.fmb ops\$yd/yd@pfs Compile_All=YES
f60gen /backup01/pfs/sy/frm/rf930oc0.fmb ops\$yd/yd@pfs Compile_All=YES
f60gen /backup01/pfs/sy/frm/rf940oc0.fmb ops\$yd/yd@pfs Compile_All=YES
f60gen /backup01/pfs/sy/frm/rf950oc0.fmb ops\$yd/yd@pfs Compile_All=YES
f60gen /backup01/pfs/sy/frm/rf001oc0.fmb ops\$yd/yd@pfs Compile_All=YES
f60gen /backup01/pfs/sy/frm/rf810oc0.fmb ops\$yd/yd@pfs Compile_All=YES
...

I have tried "sed" in my script:

cat myfile.log | sed s/\/backup01/f60gen \/backup01 > f1.log
cat f1.log | sed s/.fmb/.fmb ops\$yd/yd@pfs Compile_All=YES > myfile.log


and am getting the following error:

sed: Function s//backup01/f60gen cannot be parsed.
sed: Function s/.fmb/.fmb cannot be parsed.


Thanks a lot for a solution or any simple alternatives.

Best Regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
11 REPLIES 11
H.Merijn Brand (procura
Honored Contributor

Re: Simple question for sed/awk/perl experts

# perl -ple 's{(.*)}{f60gen $1 ops\\$yd/yd\@pfs\nCompile_All=YES}

not tested
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: Simple question for sed/awk/perl experts

add missing trailing quote yourself :)
Enjoy, Have FUN! H.Merijn
Christian Gebhardt
Honored Contributor
Solution

Re: Simple question for sed/awk/perl experts

Hi
awk '{printf("f60gen %s ops\$yd/yd@pfs Compile_All=YES \n",$0)}' inputfile

Chris
Pete Randall
Outstanding Contributor

Re: Simple question for sed/awk/perl experts

Yogeeraj,

You're very close - you just need a trailing / in your sed command:

cat myfile.log | sed s/\/backup01/f60gen \/backup01/ > f1.log

(the trailing / is between "backup01" and "> f1.log"

Same thing in the second case.

I think that should do it.

Pete

Pete
H.Merijn Brand (procura
Honored Contributor

Re: Simple question for sed/awk/perl experts

and replace the \n with a space. The forum wrapped your example, and, since I don't know f60gen, I presumed these on a new line. Reading the awk solution showed me you meant it to be the last argument
Enjoy, Have FUN! H.Merijn
Yogeeraj_1
Honored Contributor

Re: Simple question for sed/awk/perl experts

hi all,

Chris: Wonderful it works! Thanks.


procura: or should i call you "perl" master? ;) Thanks a lot. Although i gave a hard task of "add missing trailing quote".

It was as if i was asking you a tip on the phone :)

Problem solved. period.


Best Regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: Simple question for sed/awk/perl experts

hi again

pete:
Encouraging reply. however does not work :(.

still giving me error:

sed: Function s//backup01/f60gen cannot be parsed.

Procura:
I am a bit lost! where do i specify my file as argument?

Thanks a lot
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Christian Gebhardt
Honored Contributor

Re: Simple question for sed/awk/perl experts

Hi

sed Version

sed -e 's/\/backup01/f60gen \/backup01/' -e 's/fmb/fmb ops$yd\/yd@pfs Compile_All=YES/' infile
Chris

H.Merijn Brand (procura
Honored Contributor

Re: Simple question for sed/awk/perl experts

# perl -ple 's{(.*)}{f60gen $1 ops\\$yd/yd\@pfs Compile_All=YES} ' filename

or

# perl -ple 's{(.*)}{f60gen $1 ops\\$yd/yd\@pfs Compile_All=YES} ' < filename

or

# script_to_generate_list |
# perl -ple 's{(.*)}{f60gen $1 ops\\$yd/yd\@pfs Compile_All=YES} '
Enjoy, Have FUN! H.Merijn
Yogeeraj_1
Honored Contributor

Re: Simple question for sed/awk/perl experts

thank chris.

that was great!

Everything is working fine here!

Cheers
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: Simple question for sed/awk/perl experts

hi all,

with all your helps, my fully working script now looks as follows:
============================================================
#!/bin/sh
DIR=/backup01/pfs

find ${DIR} -xdev -type f -name '*.fmb'|sed -e 's/\/backup01/f60gen \/backup01/' -e 's/fmb/fmb ops$yd\/yd@pfs Compile_All=YES/' > compile_all.sh
find ${DIR} -xdev -type f -name '*.mmb'|sed -e 's/\/backup01/f60gen \/backup01/' -e 's/mmb/mmb ops$yd\/yd@pfs Compile_All=YES module_type=menu/' >> compile_all.sh
find ${DIR} -xdev -type f -name '*.pll'|sed -e 's/\/backup01/f60gen \/backup01/' -e 's/pll/pll ops$yd\/yd@pfs Compile_All=YES module_type=library/' >> compile_all.sh
#end-YD
============================================================

thank you forum!

Cheers
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)