Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk parse variable

Status
Not open for further replies.

ancadmihai

Technical User
Apr 26, 2007
4
SE
hello

i have this script (script_exp)

#!/bin/bash

echo " 2007-04-25 " >> expirati.txt
awk -F"," '{if ($26=="2007-04-25") print $1,$18,$19,$21,$23,$26}' SDP1.DUMP_subscriber.csv_200704252330_2000 >>expirati.txt
awk -F"," '{if ($26=="2007-04-25") print $1}' SDP1.DUMP_subscriber.csv_200704252330_2000 > expired20070425.txt


i need to do something like this

./script_exp var1 var2

i tried many versions of this script (including the tips from but with no good results.the last version looks like this:


#!/bin/ksh

echo "data"
read VAR

awk -v var="$VAR" -F"," '($26=="$VAR") {print $1,$18,$19,$21,$23,$26}' SDP1.DUMP_subscriber.csv_${1}2330_2000 >>ti.txt"

but i had the following error "awk: syntax error near line 1
awk: bailing out near line 1"


PLEEEASSEEEE help me out.. i can't seem to get my head around this awk and it's way of dealing with "$
 
Either:
[tt]awk -v var="$VAR" -F"," '($26==var) {...[/tt]
Or:
[tt]awk -F"," '($26=="'$VAR'") {...[/tt]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thanks a lot. you're a life saver :)
the second version worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top