If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Shell Script Store variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-02-08, 20:16
mogra mogra is offline
Registered User
 
Join Date: Mar 2008
Posts: 2
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.
Reply With Quote
  #2 (permalink)  
Old 03-03-08, 02:06
mogra mogra is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On