06252007_template.twj to 06252007_abc.twj


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 06252007_template.twj to 06252007_abc.twj
# 1  
Old 08-22-2010
06252007_template.twj to 06252007_abc.twj

Hi,

I am working in the SH shell. I have a bunch of files in a directory dir/
06252007_template.twj
06262007_template.twj
06272007_template.twj
...

Now I want to duplicate these files to
06252007_abc.twj
06262007_abc.twj
06272007_abc.twj
...

I was wondering if there was a simple way like a one liner to do this task.

I have another thing to do after this. In each of the xxxx2007_template.twj files there is a string XXXXX|YYYYY, which I want to replace with the string 70|AAPL in the newly created xxxx2007_abc files.

I was wondering if there a smart way to do this.

Thanks in advance.
# 2  
Old 08-22-2010
Like this?
Code:
for i in *template*; do 
  sed 's/XXXXX|YYYYY/70|AAPL/' "$i" > "${i%%_*}_abc.twj"
done

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 08-22-2010
Absolutely brilliant! so much done in just three lines. Thanks a lot!

Last edited by axed; 08-22-2010 at 08:33 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question