Return path of specific tag using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Return path of specific tag using awk
# 1  
Old 11-15-2016
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:

"plugin": "/rundb/api/v1/plugin/49/" is found and /results/analysis/output/Home/Auto_user_S5-00580-11-Medexome_74_042/plugin_out/FileExporter_out.81" is the path

Thank you Smilie.

awk
Code:
awk -F'"[]},:]* *"*' -v RS='{' '
function pA(arg, string) {
	string = arg
	sub(/_R_.*/, "", string)
	return string
}
{for(i = 2; i < NF - 1; i++) {
     if($i == "path") {
     if($(i + 2) == "plugin" &&
        $(i + 3) == "/rundb/api/v1/plugin/49/") {
          found = 1
          print (u = $(i+1))
          sub(/.*_user_/, "", u)
          sub(/_.*/, "", u)
          sub(/^/, "user_", u)
          i += 3
          }
            continue
          }
      	  }
}' index.html | sed '/_tn_/d'> testout

testout desired output
Code:
/results/analysis/output/Home/Auto_user_S5-00580-11-Medexome_74_042/plugin_out/FileExporter_out.81
/results/analysis/output/Home/Auto_user_S5-00580-10-Medexome_73_040/plugin_out/FileExporter_out.78
/results/analysis/output/Home/Auto_user_S5-00580-9-Medexome_70_038/plugin_out/FileExporter_out.70
/results/analysis/output/Home/Auto_user_S5-00580-8-Medexome_69_036/plugin_out/FileExporter_out.69
/results/analysis/output/Home/Auto_user_S5-00580-7-Medexome_68_034/plugin_out/FileExporter_out.68
/results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67

# 2  
Old 11-15-2016
It was this line $(i + 3) == "/rundb/api/v1/plugin/49/") { that changed in the API. I had to update it to $(i + 5) == "FileExporter") { to get the desired results. Thank you Smilie.
# 3  
Old 11-16-2016
Hi cmccabe,
where function pa is being used.?
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

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

3. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: cmccabe
1 Replies

4. UNIX for Dummies Questions & Answers

Enter carriage return in xml file after each tag (> sign)

I have an xml file which is generated in a single line an looks like this <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Batch_Id="1999996" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><some data....><some data....>closing lines...... I need to have a separate line... (3 Replies)
Discussion started by: vx04
3 Replies

5. Shell Programming and Scripting

Extracting Tag along with specific lines

I have this input file: and the desired output is as follows: Desired Output This is a sample taken from a huge file. Basically, the script should take the tag (TDK11..1>) add everything that has bukle=A until it sees the blank lines. Then takes the next tag (TDK2222>) adds everything that... (4 Replies)
Discussion started by: Ernst
4 Replies

6. Shell Programming and Scripting

sed, awk [TAG]$content[/TAG] How to get var in $content in textfile?

Hello, I got a Qstion. Im posting to a phpbb forum with bash and curl.. i have a text file with the following tags that i post to the forum: $var1 $var2 $var3 How can i with sed or awk put var content from shell script between the ... in the... (7 Replies)
Discussion started by: atmosroll
7 Replies

7. UNIX for Dummies Questions & Answers

return a specific row using awk

Hello, I am using awk to process a file, and need to return a row that meets specific criteria. awk 'BEGIN{sets variables} {processes file, updates variables} END{need to print a row that meets the criteria in one of the variables} I have tried code in the END block like {print NR==var}... (1 Reply)
Discussion started by: badPuppy
1 Replies

8. UNIX for Dummies Questions & Answers

tag/mark a file with current absolute path

Hi all, I need to mark a file with it's current location in the file system before being moved. This will enable the file to be restored back to it's original location. Can anyone provide any ideas about the best way to do this, at present i'm trying to use readlink -m to strip off the... (1 Reply)
Discussion started by: skinnygav
1 Replies

9. Shell Programming and Scripting

how to get specific xml tag ?

sorry to trouble u guys again... i have this document here called record.txt and it contains this: 2005-12-05 10:53:17,551 INFO - message received... 2005-12-05 10:53:17,557 INFO - The XML message **************<berth_allocation xmln... (13 Replies)
Discussion started by: forevercalz
13 Replies

10. Shell Programming and Scripting

SED - How to return PATH from PATH/NAME

Hi, How can I get /usr/people/me/ from /usr/people/me/file.abc with sed? Thanks... (2 Replies)
Discussion started by: cybotic
2 Replies
Login or Register to Ask a Question