Scripting with awk: facing problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting with awk: facing problem
# 1  
Old 05-02-2012
Scripting with awk: facing problem

Hi,
I wants to print the 9th column information with its path name in some txt file. Here is one line which works fine for me:
Code:
 rfdir /castor/cern.ch/user/s/sudha/forPooja | grep data | awk '{print "rfio:///castor/cern.ch/user/s/sudha/forPooja/"$9}' > dataFilenames.list

rfdir=="ls -ltr"
So with this definition of rfdir, it goes to particular folder, check the content. Grep the column with "data" and print the 9th column in datafilenames.list.

But this line is bit hard coded. I thought of making a flexible script. I could do little.

Code:
#!/bin/bash                                                                                                                                                            

PATHNAME=$1
#CONSTANT="rfio:"                                                                                                                                                      
GREP=$2
OUTPUT=$3
echo "Copying \"$1 | grep $2\" to $3"

rfdir $PATHNAME | grep $2 | awk '{print '$1'$9}'  > $3
echo "progressing ... please be patient..."

The error with this try.sh script is following:
Code:
[lxplus252] /afs/cern.ch/work/p/pooja/scripts/PhoOptStudy/mc/fall11/GJet > ./try.sh /castor/cern.ch//user/p/pooja/WorkArea/Fall11/GammaJet/GJet30To50/ bkg pooja.log
Copying "/castor/cern.ch//user/p/pooja/WorkArea/Fall11/GammaJet/GJet30To50/ | grep bkg" to pooja.log
awk: {print /castor/cern.ch//user/p/pooja/WorkArea/Fall11/GammaJet/GJet30To50/$9}
awk:                    ^ syntax error
progressing ... please be patient...
[lxplus252] /afs/cern.ch/work/p/pooja/scripts/PhoOptStudy/mc/fall11/GJet >

I did google, but unable to figure out the solution so far.

Kindly help


Many Thanks,
Pooja
# 2  
Old 05-02-2012
Hi, you could try something like this:
Code:
rfdir "$PATHNAME" | grep "$2" | awk '{print "'"$1"'"$9}' > "$3"

But something like this would be cleaner:
Code:
rfdir "$PATHNAME" | grep "$2" | awk '{print path $9}' path="$1" > "$3"

# 3  
Old 05-02-2012
Thanks..Smilie

it did work..

Pooja
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Scripting awk Problem

I'm limited in my skills related to *nix and I'm even more limited in my skills related to shell scripting and the use of awk. I have what should be a relatively simple shell script that looks in the /etc/fstab to see if a particular partition exists on the Linux system. The intention of this part... (2 Replies)
Discussion started by: DisabledVet
2 Replies

2. AIX

facing problem using su

Hi, I am able to login using su - or su directly , # prompt is coming, it doesnt ask for password. any normal user on aix system is login using su - or su . Please suggest where to change the configuration direct root login is disabled in /etc/ssh/sshd_config file. (0 Replies)
Discussion started by: manoj.solaris
0 Replies

3. Shell Programming and Scripting

Problem facing in using awk command

Hi., I am not able to replace the string with another string using gsub fn of awk command. My code: awk 'BEGIN gsub(004,IND,004)' p.txt and my i/p file p.txt is of the format: av|004|adkf|Kent,004|s av|005|ssdf|Kd,IT park|s . . . and my desired o/p should be of : (13 Replies)
Discussion started by: av_vinay
13 Replies

4. Shell Programming and Scripting

problem facing in if -else condition

can u plz tell me where is the error echo enter the filename to be searched read fname if #-d $fname then echo file exists if then echo itsa directory elif then echo its readable cat $fname else echo its not readable fi else ... (1 Reply)
Discussion started by: gotam
1 Replies

5. Shell Programming and Scripting

Problem facing with sed and awk

Hi All, I have a got a problem .. I have t files as below: 1.txt contains ----- ----- ----- column 1, "cat", column 24, "dog", column 100, "rat", ----- ----- ----- 2.sh should contain ----- ----- ----- awk 'BEGIN { printf ("%1s","cat")}' (19 Replies)
Discussion started by: jisha
19 Replies

6. Shell Programming and Scripting

AWK scripting problem - appending values

ABC:10:A1:ABCA110 ABC:10:A1:ABCA110 ABC:20:A1:ABCA120 DEF:20:D1:DEFD120 GHI:30:G1:GHIG130 GHI:40:G1:GHIG140 JKL:30:J1:JKLJ130 MNO:10:M1:MNOM110 What I'm trying to do is look through a file that consists of four columns (as above). As you can see there are duplicates in the file, i.e.... (2 Replies)
Discussion started by: rowntree
2 Replies

7. Solaris

please help as i am facing problem with uptime

Hi I am getting the uptime output as follows 12:40am up 4 day(s), 18:29, 2 users, load average: 38.97, 36.54, 34.89 The load average is too high . I have checked the processes , but no process is taking too much cpu time Please help (3 Replies)
Discussion started by: guy009
3 Replies

8. UNIX for Dummies Questions & Answers

facing a problem in redirection

Hi, I am doing this perl script print (@line(1..15)); the lines 1 to 15 get printed... how can i redirect this to file? thanks and regards vivek.s (4 Replies)
Discussion started by: vivekshankar
4 Replies

9. Shell Programming and Scripting

awk scripting problem

I'm creating an oracle insert statement using awk but need to be able to escape the ' (forward single quote) as the oralce insert syntax requires these quotes. I've tried \ in and out of quotes etc. It's these single quotes values (' .....') cat $1 | awk -F"|" '{print "insert into table... (2 Replies)
Discussion started by: jinky
2 Replies
Login or Register to Ask a Question