Calling array inside awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling array inside awk
# 1  
Old 02-07-2012
Calling array inside awk

Hello I have the file df.tmp
FS[1] is actually the / FS but escape character\ and end of line $ is used in order to fetch exctly / and not other filesystems.
awk '/\/$/ {print $(NF-1)+0}' df.tmp will work properly and return a value eg. 60
but when I am trying to issue the command with the array variable it will not work.

Please for your help.

Code:
FILE:
---------
(SERVER1)/export/home/>cat df.tmp
rpool/ROOT/s10u9 14680064 4972219 3416388 60 /
...
...
...
 
SCRIPT:
---------
#!/bin/ksh
FS[1]="\/$"
awk '/${FS[1]}/ {print $(NF-1)+0}' df.tmp

Thank you in advance for your help.
# 2  
Old 02-07-2012
Try:

Code:
#!/bin/ksh
FS[1]="\/$"
awk '/'"${FS[1]}"'/ {print $(NF-1)+0}' df.tmp

This User Gave Thanks to knight_eon For This Post:
# 3  
Old 02-07-2012
It works.

Thanks a lot
# 4  
Old 02-07-2012
Welcome Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed inside the awk script to replace a string in the array

The requirement is i need to find an array value matching with pattern {5:{ , replace that with 5: and reassign that to same array index and print it. I write something like below and the issue is sed command is not working. If i replace " with "`" the script gives syntax error.how can i... (8 Replies)
Discussion started by: bhagya123
8 Replies

2. Shell Programming and Scripting

Calling one script inside another

Hi, I am calling a script log.sh from output.sh. Log.sh has below pice of code: IFILE=/home/home1/Report1.csv if awk -F, '$6==0 && $7==0{exit 1}' ${IFILE} then awk -F, ' BEGIN{ c=split("1,6,2,3,4,5,6", col) print "To: abc@gmail.com" print "Subject: Error... (2 Replies)
Discussion started by: Vivekit82
2 Replies

3. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

4. Shell Programming and Scripting

printing array elements inside AWK

i just want to dump my array and see if it contains the values i am expecting. It should print as follows, ignore=345fht ignore=rthfg56 . . . ignore=49568g Here is the code. Is this even possible to do? please help termReport.pl < $4 | dos2ux | head -2000 | awk ' BEGIN... (0 Replies)
Discussion started by: usustarr
0 Replies

5. Shell Programming and Scripting

calling a method inside awk

Hi All, How do we call a method existing in another file inside awk. After matching a pattern i want to call a method secureCopy that exists in another file, but method not getting called: ls -l | awk -v var2=$servername -v var1=$srcserverpath -v var3=$tgtpath '... (1 Reply)
Discussion started by: abhinav192
1 Replies

6. Shell Programming and Scripting

using array inside awk

Hi All, I have the following code sequence for reading some bulk file and moving the content to two different arrays. while read data do THREEG_PATTERN=`echo $data | egrep "3G"` if then NEW_THREEG_PATTERN=`echo $THREEG_PATTERN | cut -d " " -f2` ... (12 Replies)
Discussion started by: subin_bala
12 Replies

7. Shell Programming and Scripting

split and making an array inside another array

I want to run an awk split on a value that has been pushed through an array and I was wondering what the syntax should be?? e.g. running time strings through an array and trying to examine just minutes: 12:25:30 10:15:13 08:55:23 awk ' NR==FNR{ ... (2 Replies)
Discussion started by: dcfargo
2 Replies

8. UNIX for Advanced & Expert Users

calling external values inside awk command

I have a code as follows awk ' BEGIN{FS=OFS=","} { n=split($3,a1,"~") split($4,a2,"~") split($5,a3,"~") for(i=1;i<=n;i++) { print $1,$2,a1,a2,a3,date } }' file In the above code I need to add current date(date). How is this possible to call an date or a exported value... (13 Replies)
Discussion started by: tkbharani
13 Replies

9. Shell Programming and Scripting

calling function inside awk

Hi All, My 1.txt contains some functions fun1() .... .... fun2() .... .... I can call these fun from 2.txt inside awk as below value="`fun1 "argument1"`" awk 'BEGIN {printf ("%s", "'"$value"'")}' I need to modify the above code so that without using the variable to store... (2 Replies)
Discussion started by: jisha
2 Replies

10. Shell Programming and Scripting

looping a array inside inside ssh is not working, pls help

set -A arr a1 a2 a3 a4 # START ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS integer j=0 for loop in ${arr} do printf "array - ${arr}\n" (( j = j + 1 )) j=`expr j+1` done EOS # END ========= this is not giving me correct output. I... (5 Replies)
Discussion started by: reldb
5 Replies
Login or Register to Ask a Question