AWK Variable assignment issue Ksh script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK Variable assignment issue Ksh script
# 1  
Old 08-22-2011
Error AWK Variable assignment issue Ksh script

Hi There,
I am writing a ksh script which assigns variable values from file "A" and passes that variables to file "B". While passing the parameters an additional "$" sign is being assigned to awk -v option.
Could any one help me with this please.
head -1 usr_soft_list_192.168.154.2.tmp |cut -d, -f2- |while read line
  sid=$(echo $line |cut -d, -f4)
  echo $sid
  vid=$(echo $line |cut -d, -f5)
  echo $vid
  dum=$(echo $line |cut -d, -f6)
  echo $dum
  cat std_soft.tmp |awk -F, -v var1=$sid -v var2=$vid -v var3=$dum '$5 == var1 && $6 == var2 && $7 == var3 {print }' >> x

Below is the out put with for your referene
 ksh -x 1
+ head -1 usr_soft_list_192.168.154.2.tmp
+ cut -d, -f2-
+ read line
+ echo $',APPSRV1,AS,200,16016,jdk-6u20-linux-i586.bin\r'
+ cut -d, -f4
+ sid=200
+ echo 200
+ echo $',APPSRV1,AS,200,16016,jdk-6u20-linux-i586.bin\r'
+ cut -d, -f5
+ vid=16016
+ echo 16016
+ echo $',APPSRV1,AS,200,16016,jdk-6u20-linux-i586.bin\r'
+ cut -d, -f6
+ dum=$'jdk-6u20-linux-i586.bin\r':wall:
+ echo $'jdk-6u20-linux-i586.bin\r'
+ cat std_soft.tmp
+ awk -F, -v var1=200 -v var2=16016 -v var3=$'jdk-6u20-linux-i586.bin\r' '$5 == var1 && $6 == var2 && $7 == var3 {print }'
+ 1>> x
+ read line
+ exit

Last edited by Franklin52; 08-22-2011 at 09:08 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 08-22-2011
Not sure of the "$" symbol from the example you posted, can you "dos2unix" the files(usr_soft_list_192.168.154.2.tmp and std_soft.tmp) before using them in script?

Last edited by pludi; 08-22-2011 at 09:59 AM..
This User Gave Thanks to panyam For This Post:
# 3  
Old 08-22-2011
It was added by 'set -x', not awk. This is a ksh string literal:
a=$'some special \n\t chars'
echo "$a"

# 4  
Old 08-22-2011
Thanks Panyam.. its wokring Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Optimize multiple awk variable assignment

how can i optimize the following: TOTALRESULT="total1=4 total2=9 total3=89 TMEMORY=1999" TOTAL1=$(echo "${TOTALRESULT}" | egrep "total1=" | awk -F"=" '{print $NF}') TOTAL2=$(echo "${TOTALRESULT}" | egrep "total2=" | awk -F"=" '{print $NF}') TOTAL3=$(echo... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

[awk] printing value of a variable assignment from a file

Heyas Me try to print only the value of a (specific) variable assignment from a file. What i get (1): :) tui $ bin/tui-conf-get ~/.tui_rc TUI_THEME dot-blue "" "$TUI_DIR_INSTALL_ROOT/usr" "$TUI_DIR_INSTALL_ROOT/etc/tui" "$TUI_PREFIX/share/doc/tui" "$TUI_PREFIX/share/tui"... (2 Replies)
Discussion started by: sea
2 Replies

3. Shell Programming and Scripting

Variable assignment inside awk

Hi, Was hoping someone could help with the following: while read line; do pntadm -P $line | awk '{if (( $2 == 00 && $1 != 00 ) || ( $2 == 04 )) print $3,$5}'; done < /tmp/subnet_list Anyone know if it is possible to assign $3 and $5 to separate variables within the {} brackets? Thanks... (14 Replies)
Discussion started by: CiCa
14 Replies

4. Shell Programming and Scripting

issue with nawk while using variable assignment

#ifconfig -a | nawk '/{print}' inet netmask xxxxxxxxx broadcast If i assign the ip to a variable and search for the variable nothing gets printed!! # ifconfig -a | nawk -v ip= '/ip/{print}' I am not able to understand why this is happening! (6 Replies)
Discussion started by: chidori
6 Replies

5. Shell Programming and Scripting

awk issue expanding variables in ksh script

Hi Guys, I have an issue with awk and variables. I have trawled the internet and forums but can't seem to get the exactt syntax I need. I have tried using awk -v and all sorts of variations but I have hit a brick wall. I have spent a full day on this and am just going round in circles. ... (3 Replies)
Discussion started by: gazza-o
3 Replies

6. Shell Programming and Scripting

awk variable assignment-- inside braces or not?

So, in awk, I've always put my variable assignments inside of the curly braces, just like dad, and grandpa, and the 26 generations before them. But today I came upon an awk statement that had them outside the braces-- blasphemy! Seriously, though, is there any practical difference? I was... (3 Replies)
Discussion started by: treesloth
3 Replies

7. Shell Programming and Scripting

Inconsistent variable assignment issue

I am using a piece of code which is working fine in some cases and is not working in some other instances. All I am doing is grep'ing and concatenating. Below is a working scenario. $ echo $var1 REPLYFILENAME=Options_NSE1.txt.enc $ FILE_NM=`echo ${var1##*=}`.gz (Take everything after... (1 Reply)
Discussion started by: jamjam10k
1 Replies

8. Shell Programming and Scripting

variable assignment using awk

Guys, Could you please help me out. I need two values in two variables using awk from the o/p of grep. example:- grep sdosanjh <filename> sdosanjh myhostname myfilename NOW WHAT I WANT IS :- sdosanjh should be in variable (say NAME) myhostname should be in variable (say... (8 Replies)
Discussion started by: sdosanjh
8 Replies

9. Shell Programming and Scripting

awk variable assignment in a file

Hi All, I have a little awk script which uses a variable (x): awk -v x=0 'NF != 6 { ++x } END { print "This batch had " x " errors out of ", NR" records"}' But when I've tried to put the command in a file I can't seem to declare the variable. I've managed to simplify the code so that I... (4 Replies)
Discussion started by: pondlife
4 Replies

10. Shell Programming and Scripting

ksh/Linux: Variable scoping issue? Pl. help!

user_account() { set -x nodename=$1 # set userid to user0 userid="user0" echo outside:pid $$ cat $MY_DIR/user_accounts | while read line do # line="node1 user1" echo inside do: pid $$ line:$line userid:$userid poss_node=`echo $line |awk '{print $1}'`... (2 Replies)
Discussion started by: jasmeet100
2 Replies
Login or Register to Ask a Question

Featured Tech Videos