Results 1 to 7 of 7
Hey guys and gals (again!)
I have searched forever and a day online and can't seem to find any instance of what I need. In a script, I need this:
...
- 09-27-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 8
Help needed w/ awk command
Hey guys and gals (again!)

I have searched forever and a day online and can't seem to find any instance of what I need. In a script, I need this:
Some info:Code:awk '/customizedKey/ {print $3}' ezx_hardkey.cfg > temp CODE="$(cat temp)" awk -v shell_var="$CODE" '/shell_var/ {print $2}' list > name
ezx_hardkey.cfg is just a file that contains a code like this:
Once I grab that code, I store it to a var and then want to use it as the search criteria in the following awk command.Code:[hardkeySetting] carrierKey = 95ffa462-7e2f-49a9-9e6d-f8f63b2f3c40 customizedKey = ba63e2ca-089c-4a95-8e13-81522eed47a0
The reason being, I want to then do the following command to store the file name to the var NAME
However, I realize that I cannot use a var as the search criteria, at least in the form that I've concocted.Code:NAME="$(cat name)"
Is it possible to use the awk command in that manor? If not, is there another way to put this statement that I have obviously overlooked? Thanks guys/gals!
- 09-27-2007 #2
awk help
What did you expect to be in 'list' ?
You never wrote anything to it does it exist somewhere?
- 09-27-2007 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 8
Sorry!!
I didn't realize that...
the list file is like this:
there is only a space b/w the code and the nameCode:067a149d-00b4-4ba3-b839-11ab2dbd88c0 Sync 0b6c1459-2fbe-4b2e-95c9-a4f93762fa11 Calculator 0f0c629a-9524-4fc9-8429-6df7dedf394d Modem 0f0c629a-9524-4fc9-8429-6df7dedf394d Viewer 18b62bb5-bd39-4397-9076-fe912a4b6dd1 Talking Dictionary 1e6b9963-24cc-41f8-bbee-a23ae761ff81 Calendar 23723ec3-ab86-408a-86c0-f70ac6f5c153 Time 3c34a060-87eb-726f-a6e3-e7bc909d159d Platinum Sudoku 45e9c626-06be-40d0-a166-fd5b85471aa8 Business Card Reader 45e9c626-06be-40d0-a166-fd5b85471aa8 Recorder 5382eeae-3a6f-40ef-ac3a-6f85c4a7f87f Photo Editor 5af701f6-33e3-4fe6-b15e-b7ef7c986c74 Setup 5e558577-7be1-405a-a888-e65d20a2908a Video 6aff7618-c940-48d9-ad3b-3106d9a884c2 Alarm 6cd5ea93-d3e2-4cbd-ac46-9dad6ff62b46 FM Radio 95ffa462-7e2f-49a9-9e6d-f8f63b2f3c40 Internet Browser 9667de53-e43e-47bd-96ff-89c06dc3cdbd Bluetooth 9a4cdb74-34ec-415e-ba36-b8c2a35d0071 Task Manager 9faafa35-0688-4529-8310-04f215cb2d0c File Manager ba63e2ca-089c-4a95-8e13-81522eed47a0 Real Player bacc9585-ae26-4cf9-8e72-fb520709b4b0 Sim Toolkit Apps bb621a8f-c681-477f-9d15-9c4b53b37a3e Email App c1e0df66-11ef-4b33-bddb-0cbd13827312 Camera c30158ae-e2a7-4d1c-9f6c-3b079c2f4c4e Notes App ce59717d-fb23-4b7c-8800-25ce613f4042 Call List
- 09-27-2007 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:awk 'FNR==NR{a[$1]=$0;next} /customizedKey/{ print a[$3] } ' "listfile" "ezx_hardkey.cfg"
- 09-27-2007 #5Just Joined!
- Join Date
- Aug 2007
- Posts
- 8
Wow thank you ghostdog74!
I'm @ work atm, but will test this when I get home. Would you mind explaining all of that to me? I have never seen the awk command used in such a manor, thanks!! 

- 09-28-2007 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
1) awk '{....}' file1 file2 : awk process file1 then file2
2) FNR = current record number of the current file. FNR=0 when a new file is read
3) NR = number of input records awk has processed since its execution.
4) a[$1]=$0 : associative array. index are the first field values. Values are the whole record.
5) FNR==NR{ a[$1]=$0;next} : for every record in the first file, store in array
6) Once awk reach the last record, the second file is processed.
7) /customizedKey/{ print a[$3] } : get the third field of the second file, use it to get the corresponding value in array.
8) you know the rest.
For more info, read GAWK:Effective AWK programming
- 09-29-2007 #7Just Joined!
- Join Date
- Aug 2007
- Posts
- 8
Thank you so much for your time !!


Reply With Quote