LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-13-2006, 01:45 AM   #1
Mr. Asdf
LQ Newbie
 
Registered: Jul 2005
Distribution: CRUX 2.1, Debian sarge
Posts: 27

Rep: Reputation: 15
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?
 
Old 07-13-2006, 02:22 AM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 50
how about something like
Code:
awk $3' ~ $2' somefile
 
Old 07-13-2006, 07:42 AM   #3
Mr. Asdf
LQ Newbie
 
Registered: Jul 2005
Distribution: CRUX 2.1, Debian sarge
Posts: 27

Original Poster
Rep: Reputation: 15
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?
 
Old 07-13-2006, 08:26 AM   #4
Mr. Asdf
LQ Newbie
 
Registered: Jul 2005
Distribution: CRUX 2.1, Debian sarge
Posts: 27

Original Poster
Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split large file in several files using scripting (awk etc.) chipix Programming 14 10-29-2007 11:16 AM
Forum on scripting, sed, awk, etc.?? pixellany Programming 3 12-01-2005 01:16 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
awk scripting question di11rod Linux - Software 11 04-01-2005 02:47 PM
csh zaza Linux - Newbie 6 05-21-2002 06:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration