perl -plne

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

perl -plne

Mary
Is there a way to arrange this command to repeat in a script and edit the same text file?
ie:
$ perl -plne 'print "Cygwin" if(/Fedora/);' file

perl -plne 'print "Check Started" if(/Invoke/);' file > output_file

perl -plne 'print "Check Successful" if(/Inserted/);' file > output_file

etc. etc within a script

Also, since I am editing a long file it would not let me add \i to the front of my print statement not \n to the end of my print statement?

Thank You!!
Reply | Threaded
Open this post in threaded view
|

Re: perl -plne

Guru
Administrator
  The question is not clear. Can you please explain what are you looking for?
Reply | Threaded
Open this post in threaded view
|

Re: perl -plne

Mary
Yes, Thank you for your help - I am new to this!
I am trying to insert print statements into a log a file in front of a word that is searched. I am able to accomplish this task, by using the following small script:

script - each print statement inserted 1 by 1/manually copy.txt file/source/repeat


(1st insertion)
perl -plne 'print "i Printf(I[stdcell_pwr_check]:RAN CHECK FOR STDCELL_PWR MENU INVOKED.)" if(/fdkPowerConnectCreateFormInvoke/);' logpro.txt > logpro2.txt

(2nd insertion - copy the output.txt file - Uncomment 2nd search - comment out 1st insertion - source)
#perl -plne 'print "i Printf(I[stdcell_pwr_check]:SUCCESSFUL POWER VIAS INSERTED.)" if(/Inserted/);' logpro2.txt > logpro3.txt

(etc. etc. The above works)
Is there an easy way to stack my search/insert requests and ony source the script once?

Also,
my print insertion texts should include a    \i    at the start     and \n;    at the end. When I try to
include these, the \i is dropped and does not appear and the \n; executes and puts a new blank
line into the log file. I can use nedit to manually search my log and add these in as a solution,
but is there a way to include these in my original print statements? The new file I am creating
needs to be read into skill.



Reply | Threaded
Open this post in threaded view
|

Re: perl -plne

Guru
Administrator
You can use a kind of config file which contains something like:

fdkPowerConnectCreateFormInvoke:I[stdcell_pwr_check]:RAN CHECK FOR STDCELL_PWR MENU INVOKED.
Inserted:I[stdcell_pwr_check]:SUCCESSFUL POWER VIAS INSERTED.

  Create a perl script which will first read this config file and have it in a hash. Then parse the input file and do the pattern matching and substitution.  Let us know once you try this.