awk to print string if tag is specific value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to print string if tag is specific value
# 1  
Old 09-26-2016
awk to print string if tag is specific value

In the below awk I am trying to print expName only if another tag planExecuted is true. In addition to the expName I am also printing planShortID. For some reason the word experiment gets printed so I remove it with sed. I have attached the complete index.html as well as included a sample of it in file. The awk does run but the output is empty. I was following a code from @ Don Cragun but I am doing something wrong. Thank you Smilie

awk
Code:
awk -F'"[]},:]* *"*' -v RS='{' '
{for(i = 2; i < NF - 1; i++) {
     if($i == "expName" &&
        $(i + 2) == "planExecuted" &&
        $(i + 3) == "true")
          print $(i+1) RS $(i+43)
 }
}' file | sed '/experiment/d' > out

file
Code:
{"meta": {"limit": 20, "next": "/rundb/api/v1/plannedexperimentdb/?offset=20&limit=20&format=json", "offset": 0, "previous": null, "total_count": 52}, "objects": [{"adapter": null, "applicationGroup": "/rundb/api/v1/applicationgroup/1/", "autoName": null, "categories": "", "childPlans": [], "controlSequencekitname": null, "cycles": null, "date": "2016-09-21T19:03:28.000079+00:00", "expName": "R_2016_09_21_14_01_15_user_S5-00580-9-Medexome", "experiment": "/rundb/api/v1/experiment/70/", "id": 78, "irworkflow": "", "isFavorite": false, "isPlanGroup": false, "isReusable": false, "isReverseRun": false, "isSystem": false, "isSystemDefault": false, "libkit": null, "libraryReadLength": 200, "metaData": {}, "pairedEndLibraryAdapterName": "", "parentPlan": null, "planDisplayedName": "Medexome", "planExecuted": true, "planExecutedDate": null, "planGUID": "00212eae-ba3d-4b1e-8496-cc1dbd9a9748", "planName": "Medexome", "planPGM": null, "planShortID": "RLNI0", "planStatus": "run", "preAnalysis": true, "project": "medexome_validation", "projects": ["medexome_validation"], "qcValues": [{"id": 208,

desired result
Code:
R_2016_09_21_14_01_15_user_S5-00580-9-Medexome
RLNI0

# 2  
Old 09-26-2016
No surprise your output is empty, as your compound if condition won't ever be true with either of your input files. When a field $i == "expName", there's no "planExecuted" nor "true" anywhere nearby. Please reconsider/refine your condition.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to match file1 and extract specific tag values

File2 is tab-delimeted and I am trying to use $2 in file1 (space delimeted) as a search term in file2. If it is found then the AF= in and the FDP= values from file2 are extracted and printed next to the file1 line. I commented the awk before I added the lines in bold the current output resulted. I... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

Return path of specific tag using awk

The below awk is used with the attached index.html and matches the specific user id in the sub portion with path of /rundb/api/v1/plugin/49/. The command does run but the output is blank. Something changed in the file structure as it used to work. So using the first line in the output: ... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk - how to print specific field if a string is matched

hi gurus, I would like to be able to use awk to process 1 file as such: abc 1 2 3 4 5 6 7 8 9 10 flags 1 2 4 flags 1 2 5 abc 2 3 4 5 6 7 8 9 10 11 flags 1 2 3 abc 4 5 6 7 8 9 6 7 78 89 flags 1 2 3 flags 1 2 4 flags 1 2 3 4 I would like to be able to print field 1 and 5 when the... (4 Replies)
Discussion started by: revaroo
4 Replies

4. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

5. Shell Programming and Scripting

Search for a html tag and print the entire tag

I want to print from <fruits> to </fruits> tag which have <fruit> as mango. Also i want both <fruits> and </fruits> in output. Please help eg. <fruits> <fruit id="111">mango<fruit> . another 20 lines . </fruits> (3 Replies)
Discussion started by: Ashik409
3 Replies

6. Shell Programming and Scripting

Print String Every Specific Line

Dear All, I have input file like this, 001 059 079 996 758 079 069 059 079 ... ... Desired output: AA 001 BB 059 (4 Replies)
Discussion started by: attila
4 Replies

7. UNIX for Dummies Questions & Answers

How to Detect Specific Pattern and Print the Specific String after It?

I'm still beginner and maybe someone can help me. I have this input: the great warrior a, b, c and what i want to know is, with awk, how can i detect the string with 'warrior' string on it and print the a, b, and c seperately, become like this : Warrior Type a b c Im still very... (3 Replies)
Discussion started by: radynaraya
3 Replies

8. Shell Programming and Scripting

Need awk help to print specific columns with as string in a header

awk experts, I have a big file of 4000 columns with header. Would like to print the columns with string value of "Commands" in header. File has "," separator. This file is on ESX host with Bash. Thanks, Arv (21 Replies)
Discussion started by: arv_cds
21 Replies

9. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

10. Shell Programming and Scripting

search a word and print specific string using awk

Hi, I have list of directory paths in a variable and i want to delete those dirs and if dir does not exist then search that string and get the correct path from xml file after that delete the correct directory. i tried to use grep and it prints the entire line from the search.once i get the entire... (7 Replies)
Discussion started by: dragon.1431
7 Replies
Login or Register to Ask a Question