LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   command application problem (http://www.linuxquestions.org/questions/programming-9/command-application-problem-495841/)

mkingiii 10-26-2006 03:55 PM

command application problem
 
I have several files, each of which contain lists of files. What I need to do is replace text in each of the files in the lists. Each of the files in the lists have a similiar designation:

./aa#/prod/#/#/final.pdb

The command sequence I am trying to employ is as follows:

gunzip ./aa#/prod/#/#/final.pdb.gz ; perl -pi -
e 's/YSN/LYS/g' ./aa#/prod/#/#/final.pdb ; gzip ./aa#/prod/#/#/final.pdb

The way I am trying to do it right now is to go copy the orginal file(#.file) containing the list of files into three new files (#.unzip, #.rep, and #.zip). I then open each of the new files using emacs, and find and replace ./ and .pdb with the respective commands. This is a bit of a time consuming process. I would greatly appreciate help if there a way better way to implement the commands.

mkingiii 10-26-2006 04:07 PM

I guess what I would want to know is if there is a way to create a generic program file containing the command sequence I need to employ with place holders for the specific files from the lists. Something like:

gunzip xxx.gz ; perl -pi -e 's/YSN/LYS/g' xxx ; zip xxx

Then tell this program file to run the commands on the contents of the files containing the lists.

mkingiii 10-26-2006 07:01 PM

Not to be rude, but no one has any ideas? I see that people have viewed my post. If this isnt the right place for my post or if what I want to do isnt even possible please tell me. I have spent all day on google trying to figure out a way to do it. I am a novice at linux, so please help.

ntubski 10-26-2006 09:48 PM

Code:

for file in ./aa*/prod/*/*/final.pdf.gz; do
  gunzip $file --to-stdout | perl -p -e 's/YSN/LYS/g' |gzip > $file
done

I'm not sure if this text substitution is going to do what you want, pdf files don't have the text you see in a pdf viewer endcoded as ascii...

Note that I told gunzip to send the file to standard out so that I wouldn't have to worry about the change in the filename.

mkingiii 10-27-2006 01:24 AM

Thanks, I will run a few tests and see if that works.


All times are GMT -5. The time now is 09:44 AM.