03-05-2008
AWK with a variable - am I missing something??
I've got a file - for example:
A B C D E
21134570 1 21573 XXXX XXXX
21134570 1 21574 XXXX XXXX
21134570 1 21575 XXXX XXXX
21134577 1 21569 XXXX XXXX
21134571 1 21566 XXXX XXXX
21134566 1 21536 XXXX XXXX
21134560 1 21555 XXXX XXXX
I have a line of code that will get a value from column "A" based on some other requirements (stored in variable: CurrentAValue)
I want to get column C value for the current A value
I've tried:
var=`awk '$1 ~ $CurrentAValue { print $3 }' $FILE | sed -n "$1 p"`
Am I missing something? It won't work correctly.
I'v also tried
awk -v val=$CurrentAValue '$1 ~ $val { print $3 }' $FILE | sed -n "$1 p"`
and it gives me an error stating that val must be between 0 and 199
I've tried many things:
$1 ~ /$CurrentAValue/
$1 ~ "/$CurrentAValue/"
$1 ~ /"$CurrentAValue"/
What am I missing? I'm sort of new to shell scripting so I'm sure there is just something I'm not aware of.
Thanks for any help!!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Here is what I am trying to do:
I have a list of numbers that I pulled from an awk command in a column like so:
1
3
4
7
8
I want to find which numbers in the list are missing out of a range. So let's say I want to find out from the list above which numbers are missing from the... (6 Replies)
Discussion started by: afavis
6 Replies
2. Shell Programming and Scripting
Hey ,
I'm trying to perform the following command, however it cannot read the variable assigned earlier. I'm not sure why this happen. Please help thanks
while :
do
echo "what's ur name? (if none just press )"
read name
changeName = echo $name | sed "s/on/ey/"
echo $changeName #this... (8 Replies)
Discussion started by: sexyTrojan
8 Replies
3. Shell Programming and Scripting
Hi Experts,
The content of the raw file:
date,nomsgsent,nomsgnotdeliver,nomsgdelay
201003251000,1000,1,2
201003251000,900,0,0
201003251000,1450,0,0
201003251000,1230,0,0
However, sometimes, the column will missing in the raw files:
e.g.
date,nomsgsent,nomsgdelay... (8 Replies)
Discussion started by: natalie23
8 Replies
4. Shell Programming and Scripting
Hi all,
Hope someone can help me out here.
I have this BASH script (see below)
My problem lies with the variable path.
The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level.
The... (6 Replies)
Discussion started by: Cowardly
6 Replies
5. Shell Programming and Scripting
Hello to all,
I have show below a file separated by commas. In first column has numbers where the last number is 13.
1,4
2,6
3,7
5,2
6,5
7,5
8,65
9,10
11,78
13,2
What I want to know is which numbers are missing from 1 to 13 (in this case 13 is last number in column 1). My real... (17 Replies)
Discussion started by: Ophiuchus
17 Replies
6. Shell Programming and Scripting
I have a file that I need to find each interface that has move-group on the interface line and print this line if the lines under the interface does Not have "filter-shared 14".
Example file:
interface 1/1/1/0 move-group
decription one one one zero
no shut
filter-shared 14... (21 Replies)
Discussion started by: numele
21 Replies
7. Shell Programming and Scripting
Hi there,
I was using the following awk statement but the first line is missing
dirlist=(`ls summary*`); #list all the files in a directory and store them into a variable
echo '<table border='1'>'
echo '<tr><td>%windir%\fonts\*.* </td><td>' ; awk '/Successfully/ {P=0} P... (2 Replies)
Discussion started by: alvinoo
2 Replies
8. Shell Programming and Scripting
Hello experts!
I have 2 files.
file1 is a list file containing uniquely names. e.g.:
name1 number number
name2 number number
name5 number number
name10 number number
...
file2 is a data file arbitrary containing the names of file1 in paragraphs separated by "10" e.g.
name4 ... (3 Replies)
Discussion started by: phaethon
3 Replies
9. Shell Programming and Scripting
I am learning AWK by trying out examples whenever I need a specific conversion. I would like to edit the 'before.txt' so that all the missing data points between 140-150 are added and shown as 0.
before.txt
145 2
148 13
149 17
to below,
140 0
141 0
142 0
143 0
144 0
145 2
146 0... (5 Replies)
Discussion started by: numareica
5 Replies
10. Shell Programming and Scripting
I am using awk to match columns and output based on those matches. For some reason it is not printing matching columns, am I missing something?
Operating system - windows with cygwin.
Command that I am using:
sed 's/]*,]*/,/g' $tempdir/file1 > $tempdir/file1.$$ && awk -F, 'FNR==NR{f2=$2... (7 Replies)
Discussion started by: dis0wned
7 Replies