Problem with using using quote in awk script

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Problem with using using quote in awk script
# 1  
Old 04-12-2012
Problem with using using quote in awk script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

i have the output of a csh script piped to an awk script. In the awk script i was trying to assign a variable with the output of a command, the problem is when i use the quote ' or ` it gave me syntax error and when i use " it printed out the command instead of its expected output

2. Relevant commands, code, scripts, algorithms:

Code:
#!/bin/csh

./a_script | awk 'BEGIN { FS="." } { num = "cat $argv[1] | grep $0 | wc -l"; printf "%s %s %s\n", $1, $0, num }'

3. The attempts at a solution (include all code and scripts):

the above

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

University of Southampton, Bob Damper, comp1005

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 04-12-2012
'cat argv' does not work inside awk. awk is not a shell language. Neither does grep or wc -l.

What does the output from a_script look like, and what do you want to do with it?
# 3  
Old 04-12-2012
Hi ymc1g11,

One way to solve the problem:
Code:
awk 'BEGIN { FS="." } { "cat $argv[1] | grep $0 | wc -l" | getline num; printf "%s %s %s\n", $1, $0, num }'

# 4  
Old 04-13-2012
Quote:
Originally Posted by Corona688
'cat argv' does not work inside awk. awk is not a shell language. Neither does grep or wc -l.

What does the output from a_script look like, and what do you want to do with it?
the output of a_script looks like the following:

Quote:
KW4912T.DOC
KW4912XS.doc
KW4912XT.pdf
KW4912GT.PDF
KW4912X.doc
KW4912ZX.doc
and my $argv[1] is actually an access log file, by using grep and the above line as argument, i want to find out how many times had the file been viewed. Yet some of the output of a_script might not been accessed b4, any help?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: single quote match in If

Hello, I'd like to print line if column 5th doesn't match with exm. But to reach there I have to make sure I match single quote. I'm struggling to match that. I've input file like: Warning: Variants 'exm480340' and '5:137534453:G:C' have the same position. Warning: Variants 'exm480345'... (9 Replies)
Discussion started by: genome
9 Replies

2. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

3. Homework & Coursework Questions

Back quote problem

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Print out problem with line follow: echo There are '$cat $fname | wc -l' contacts in database how do I replace... (2 Replies)
Discussion started by: scopiop
2 Replies

4. Shell Programming and Scripting

quote problem

Hi Everyone hwo are you i have one file "abc.txt" which contains record like this "1","2","3" "3","4","5" now i want to change above 2 to 5 so i write the code as awk ' BEGIN{FS=","} { if(NR==1) { print $1",5","$3 } else { print $0 } ' abc.txt but the outpute is "1",5,"3"... (5 Replies)
Discussion started by: aishsimplesweet
5 Replies

5. Shell Programming and Scripting

remsh problem with single quote (')

Hi All, Im executing the shell script remotely. here is one statement from that: remsh $rHost -l $rUser "java -jar $TARGET/toolkit/apps/bin/toolkit-stm.jar network -m -d1 /abmusr06/abm/users/dywrk01/$package/DYP_Execution/data/configuration/network_aus/network -u2... (1 Reply)
Discussion started by: AB10
1 Replies

6. Shell Programming and Scripting

replacing a quote in some lines with multiple quote fields

i want to replace mistaken quotes in line starting with tag 300 and relocate the quote in the correct position so the input is 223;25 224;20100428064823;1;0;0;0;0;0;0;0;8;1;3;9697;18744;;;;;;;;;;;; 300;X;Event:... (3 Replies)
Discussion started by: wradwan
3 Replies

7. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

8. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

9. Shell Programming and Scripting

single quote problem with rsync

Hi everybody, I'm a newbie and hope that someone help me in this problem. I have a filename in LINUX with single quote like this: abs@hosttest:~/ABS/BETY/cygdrive/C/DECLARANOT 1.1.4/02 - ROCK/052 - GUNSROSES> dir You* -rw-r--r-- 1 abs users 2365881 2008-08-25 09:16 You're Crazy.mp3 ... (9 Replies)
Discussion started by: mr_boysito
9 Replies

10. Shell Programming and Scripting

Problem with double quote and string variable

Hello, i have a file output.txt which contains a single line with a list of files with quotes : "file1.ext" "file2.ext" "file3.ext" In a shell script, I want to retrieve the line and use it as a variable in a command like : zip archive.zip $LIST I cant get it work. When I physically type... (6 Replies)
Discussion started by: mattemp
6 Replies
Login or Register to Ask a Question