Find the answer to your Linux question:
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 ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    8

    Combining lines in sed & awk

    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 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.

    longscript.sh is something like that
    Code:
    #### Creating folders
    mkdir 0sdfdata
    mkdir 0sdfdata/0rawsdf
    cp *.gz 0sdfdata/0rawsdf
    gunzip *.gz
    ....
    and in the end, "converter.sh" should be like that;
    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

  2. #2
    Linux 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:

    Code:
    awk -v pwd="$PWD" '{print "cd "pwd"/"$0";sh /path/to/shortscript.sh"  }' temp1 | sh
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...