Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2008
    Posts
    2

    Unanswered: Shell Script Store variable

    I have following shell script :

    #!/bin/tcsh

    foreach x (*topRank.txt)
    echo `basename $x .txt `
    PRE=`basename $x .txt`
    cut -f 1 $x | cut -d ' ' -f1 | sed 's/NAME/$PRE/' | sed 's/VC0/VC_0/' | tr "\n" "\t" >> all.log
    echo "\n" >> all.log
    end

    Overall Goal : For each file in the the current directory which ends with topRank.txt do something
    a) cut the first column of the file than further again cut the column by using space a deliminator, now replace NAME with the either just prefix of the file name or may be $x , it doesnt matter as long as the it is I know some how that this line come from this file id.
    b) replace few things
    c) now put everything on a single line with tr cmd

    Everything works ...except following.


    Problems :

    a) sed 's/NAME/$PRE/' Or sed 's/NAME/$x/' does not work it replace NAME with $PRE and $x respectively instead of the file name.
    b) also when I run the script it tells PRE command not found
    Thanks of help.

  2. #2
    Join Date
    Mar 2008
    Posts
    2
    I found the answer for 2nd mistake & for 1st one somebody in other forum helped

    Error in script

    PRE should be
    set PRE

    and sed 's/NAME/$PRE/' should be sed 's/NAME/'$PRE'/'

    It works fine.

    Thanks for viewing

Posting Permissions

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