LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   csh scripting and awk? (https://www.linuxquestions.org/questions/linux-general-1/csh-scripting-and-awk-463548/)

Mr. Asdf 07-13-2006 01:45 AM

csh scripting and awk?
 
Hi, I'm trying to write a csh script (for all you csh haters, this is a task i was given in my college studies) and in that script I want to use awk. the problem is, that in the pattern in awk, there is the $1, $2, $3 (...) variables, representing fields of the file / input. Also, in csh scripting, there are $1, $2, $3 (...) variables, representing arguments for the script.

What I want to do is to compare the second field of the awk input to the third argument of the script, but that does some problem - lets say,
Code:

#!/bin/csh

.....
awk '$3 ~ $2' somefile
.....

but that doesn't work well.
Do you know of any solutions for this problem?

spooon 07-13-2006 02:22 AM

how about something like
Code:

awk $3' ~ $2' somefile

Mr. Asdf 07-13-2006 07:42 AM

Quote:

Originally Posted by spooon
how about something like
Code:

awk $3' ~ $2' somefile

Doesn't work... how did you come up with that one?

Mr. Asdf 07-13-2006 08:26 AM

alright, found it. it is possible to do:
awk -v expression=$3 '$2 ~ expression' file
a pretty nice way.
if you know any other ways, more elegants and such, you are free to give a comment ;)


All times are GMT -5. The time now is 10:16 PM.