Results 1 to 2 of 2
Hi All,
I am trying to combine those two lines.
Code:
awk -v pwd="$PWD" '{print "cd "pwd"/"$0"" }' temp1 > converter.sh
sed -n '1,50p' longscript.sh
I have long list of ...
- 12-08-2009 #1Just Joined!
- Join Date
- Nov 2009
- Posts
- 8
Combining lines in sed & awk
Hi All,
I am trying to combine those two lines.
I have long list of commands in my longlist.sh file and it is standard. I would like to create a file and in there; first I want to enter the folder (with awk) and then by using sed, write the commands just under it.Code:awk -v pwd="$PWD" '{print "cd "pwd"/"$0"" }' temp1 > converter.sh sed -n '1,50p' longscript.sh
longscript.sh is something like that
and in the end, "converter.sh" should be like that;Code:#### Creating folders mkdir 0sdfdata mkdir 0sdfdata/0rawsdf cp *.gz 0sdfdata/0rawsdf gunzip *.gz ....
Code:cd /home/umut/mystars/star1/ #### Creating folders mkdir 0sdfdata mkdir 0sdfdata/0rawsdf cp *.gz 0sdfdata/0rawsdf gunzip *.gz .... cd /home/umut/mystars/star2/ #### Creating folders mkdir 0sdfdata mkdir 0sdfdata/0rawsdf cp *.gz 0sdfdata/0rawsdf gunzip *.gz ....
How can I just combine those two lines?
Thanks
Umut
- 12-17-2009 #2Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
If you need to run 50 lines of code in longscript.sh over and over, why don't you extract it to a shorter version, say, shortscript.sh and run it with awk this way:
Of course you have to generate shortscript.sh first (just one-time though). Also the above method eliminates the need of creating converter.sh under each directory.Code:awk -v pwd="$PWD" '{print "cd "pwd"/"$0";sh /path/to/shortscript.sh" }' temp1 | sh


Reply With Quote