AWK syntax question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers AWK syntax question
# 1  
Old 10-27-2008
AWK syntax question

Hi,

Have to check file names in some given directory.

SO, What is the right syntax here:
Quote:

>object_list="CUSTOMER ADDRESS TELEPHONE"
>file_list=`ls $DATA_PATH | awk -F"_" 'NF==5 && $1=="'$vendor'" && $2=="'$source'" && *$3*=="'$object_list'" {print $0}'`
*$3*=="'$object_list'" - just wanted to check if $3 is in the object_list.

And also, Do I need so many quotes around?
# 2  
Old 10-28-2008
why are you using * around $3 ?

The syntax is correct if you remove the * like
Code:
file_list=`ls $DATA_PATH | awk -F"_" 'NF==5 && $1=="'$vendor'" && $2=="'$source'" && $3=="'$object_list'" {print $0}'`

# 3  
Old 10-28-2008
object_list="CUSTOMER ADDRESS TELEPHONE"

Here I wanted to check if $3 is in the object_list, not equal, but part of it.
For instance if $3="CUSTOMER" - OK.
So I need something like IN or *$3* syntax, I think.

thanks.
# 4  
Old 10-28-2008
Please can u tell me how to post a new thread? i am new user here, i am not finding any link to do so! please help me...
# 5  
Old 10-28-2008
To the OP: use ~ for contains rather than == (use nawk / /usr/xpg4/bin/awk on solaris)

To the thread hijacker ;-) , shruthinagaraj, go to a particular forum where you wish to post - in the top left is a "start new thread" button...
# 6  
Old 10-28-2008
Is it ok to do it that way:

I can't do:
Quote:
awk '... $object_list ~ $3 ...'
But I can
Quote:
awk '... $3~$object_list...'
for some reasons?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question regarding quotation syntax

Hey guys, my first post on UNIX Forums(much overdue IMO)! I've got this bit of code that doesn't seem to be working correctly for an Android app I'm working on: "screen -S gmod1 -p 0 -X stuff " & "" & command.text & "`echo -ne '\015'`""" Basically it types command.text(variable determined... (4 Replies)
Discussion started by: stingwraith
4 Replies

2. Programming

Perl syntax question

Hallo everybody, I have a following problem - I'm doing a map funciont to fill in a HTML table and I want to use some radiobutton groups. Unfortunatelly, they are grouped by names, so I have to add some "counter" that will divide one row from another, and I'm using CGI.pm for generating the... (3 Replies)
Discussion started by: duskos
3 Replies

3. Shell Programming and Scripting

Question about syntax error

first of all.. sorry about all the question bombing.. im bored atm so im currently playing around with sh scripting hehe s = `expr ls -s Documents | grep Music | awk '{ print $1 }' ` t = `expr $t + $s` it give syntax error s not found t not found lol... any idea why? (7 Replies)
Discussion started by: Nick1097
7 Replies

4. Shell Programming and Scripting

tar -C syntax question

I am writing a perl script to tar multiple files (in unix) from a given directory to a given output directory. I do NOT want the file path included in the tar, so I've flagged the -C option. Example: tar -cvf tar/1.tar -C htmp/source/ 1-1-1.xml However, I need to do this for a number of target... (3 Replies)
Discussion started by: michanjohns
3 Replies

5. UNIX for Advanced & Expert Users

SNMP syntax question

Hello, I need to create an snmp.comf file that defines 2 IPs to the same community string. Do I need to have 2 community strings with the same name and diff't IPs? Or should I have 1 string and list the IPs? (comma seperated?) Example: rocommunity EC_8000_RO arguments EC_8000_RO... (2 Replies)
Discussion started by: felbvts
2 Replies

6. Shell Programming and Scripting

syntax question in regards to nested awk statements

Hello all, I am writing up an input file and I was hoping I could get some guidance as to how to best consolidate these 2 awk statements for 1 while loop. Here's my input file # cat databases.lst #NOTE: These entries are delimited by tabs "\t" #oracleSID name/pass # db11 ... (2 Replies)
Discussion started by: Keepcase
2 Replies

7. Shell Programming and Scripting

OR operator syntax question in AWK script

Hi guys, I confused about syntax used in OR script as follow: I have this sample file separated by "|" containing: January|Month No. 1 February|Month No. 2 March|Month No. 3 April|Month No. 4 May|Month No. 5 June|Month No. 6 July|Month No. 7 August|Month No. 8 September|Month No. 9... (11 Replies)
Discussion started by: cgkmal
11 Replies

8. Shell Programming and Scripting

awk syntax question

Hi I use awk command to delete the first blanc line of a file: awk '/^$/ && !f{f=1;next}1' infile > outfile can somebody please explain me what the last "1'" in !f{f=1;next}1' stands for... Thansk a lot -A (3 Replies)
Discussion started by: aoussenko
3 Replies

9. Shell Programming and Scripting

yet another awk field syntax question

I am trying to print the remaing fields and field numbers beginning with a field 'xyz' #cat abc test1:test2:xyz:test3:test4:test5 #cat def test1:test2:test3:xyz:test4:test5 desired output is to be able to print NF and any trailing fields separated by':' test3 3 or test4 3 or test5... (4 Replies)
Discussion started by: prkfriryce
4 Replies

10. Shell Programming and Scripting

awk syntax question

Hi there could someone explain what is happening in the following function/statement for me, im just a little confused code = 'BEGIN{FS=","} { printf ("%-11s,%s%s%s,%07.2f,%14s,%-3s\n",$1,substr($2,9,2),substr($2,6,2),substr($ 2,3,2),$9,$10,$12) } this function is called later in the... (2 Replies)
Discussion started by: hcclnoodles
2 Replies
Login or Register to Ask a Question