get the value from a response enclosed tag <>


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get the value from a response enclosed tag <>
# 1  
Old 10-28-2011
get the value from a response enclosed tag <>

Hi All,

I'm a newbie here, I'm having problem getting the value inside the tag of input file.

ex.
script
[unix] $ curl -H ...
response from script
<tag1>response1</tag1><tag2>response2</tag2><tag3>response3</tag3>

How to get the response from enclosed tag? is this possible?
sample output:
response1
response2
response3

Thanks,
# 2  
Old 10-28-2011
Code is specificallyt for the input you have specified...
Code:
awk -F"<|>" '{for(i=3;i<=NF;i=i+4){print $i}}' inputfile

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 10-28-2011
thank you very much Sir ahamed. but what i'm trying to say is only the "response2" under tag2. is my output.

example output:
response2

Thanks,
# 4  
Old 10-28-2011
Code:
$ nawk -F"[><]" '{print $7}' infile
response2


Last edited by jayan_jay; 10-28-2011 at 04:03 AM.. Reason: modified code based on the latest requirement..
This User Gave Thanks to jayan_jay For This Post:
# 5  
Old 10-28-2011
thank you very much Sir jayan jay.

I'm just wondering what is the meaning of your code. see below

Code:
$ nawk -F"[><]" '{print $3,$7,$11}' infile

---------- Post updated at 03:24 PM ---------- Previous update was at 03:06 PM ----------

thank you very much to all... but what i want to say is for example the input file is not consistent and a lot of enclosed tag are in the input file. what i want is only the value inside the <reason> tag. because the file is not consistent

ex.
<tag1>niks1</tag1><tag2>niks2</tag2><reason>YES</reason><pogi>oh yeah</pogi>

sometimes the input are in this format:
<tag1>niks1</tag1><reason>NO</reason><tag2>niks2</tag2>

that's why due to the inconsistent of file i want only to capture the value of <reason> tag.

Please advise,
Thanks
# 6  
Old 10-28-2011
Quote:
Originally Posted by nikki1200
thank you very much to all... but what i want to say is for example the input file is not consistent and a lot of enclosed tag are in the input file. what i want is only the value inside the <reason> tag. because the file is not consistent

ex.
<tag1>niks1</tag1><tag2>niks2</tag2><reason>YES</reason><pogi>oh yeah</pogi>

sometimes the input are in this format:
<tag1>niks1</tag1><reason>NO</reason><tag2>niks2</tag2>

that's why due to the inconsistent of file i want only to capture the value of <reason> tag.

Please advise,
Thanks
Try this:
Code:
sed 's#.*reason>\(.*\)</reason.*#\1#' file

This User Gave Thanks to Franklin52 For This Post:
# 7  
Old 10-28-2011
Thank you very much, i already got the logic. but the part that i need to the value from the enclosed tag from the response of the script without the response getting redirected to a file

script
[unix] $ curl -H ...
response from script
<tag1>response1</tag1><tag2>response2</tag2><tag3>response3</tag3>

without redirecting the response of the script to a file
sample output:
response2

Thanks,

Last edited by nikki1200; 10-28-2011 at 04:59 AM.. Reason: code change
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

3. Shell Programming and Scripting

XML Parse between to tag with upper tag

Hi Guys Here is my Input : <?xml version="1.0" encoding="UTF-8"?> <xn:MeContext id="01736"> <xn:VsDataContainer id="01736"> <xn:attributes> <xn:vsDataType>vsDataMeContext</xn:vsDataType> ... (12 Replies)
Discussion started by: pareshkp
12 Replies

4. 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

5. Shell Programming and Scripting

How to retrieve the value from XML tag whose end tag is in next line

Hi All, Find the following code: <Universal>D38x82j1JJ </Universal> I want to retrieve the value of <Universal> tag as below: Please help me. (3 Replies)
Discussion started by: mjavalkar
3 Replies

6. Shell Programming and Scripting

How to remove characters enclosed in single quotes?

How to remove characters enclosed in single quotes? My data is something like this (03/22/2011 08:17:26.650) : ( -> '1' -> '1-1-3' -> '6' -> '1' -> 'SALMOR58BB4' aaaaa bbbbbb ccccc ((dddd)) I want the output to be (03/22/2011 08:17:26.650) : ( -> -> -> -> -> aaaaa... (2 Replies)
Discussion started by: rdhanek
2 Replies

7. UNIX for Dummies Questions & Answers

find text enclosed between special characters

Hi, I'm trying to find all DISTINCT words having _mr in the line and ENCLOSED in '/'. For eg below is the text in a file.. /database/new_mr254/1 /database/rawdb/views/new_mr254/1 /database/project/rawdb/tables/new_mr232/1 /database/project/rawdb/views/new_mr253/1... (5 Replies)
Discussion started by: northwest
5 Replies

8. 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

9. Shell Programming and Scripting

Deleting part of a string enclosed in brackets

I use otool on OS X to figure out the shared libraries that a binary uses. I run this command: otool -L /Applications/Vidnik\ 0.13.0/Vidnik.app/Contents/MacOS/Vidnik And it returns an output similar to this: /Applications/Vidnik 0.13.0/Vidnik.app/Contents/MacOS/Vidnik:... (10 Replies)
Discussion started by: pcwiz
10 Replies

10. UNIX for Advanced & Expert Users

How to remove a character which is enclosed in Double quotes

I want to remove the comma which is present within the double quoted string. All other commas which is present outside double quotes should be present. Input : a,b,"cc,dd,ee",f,ii,"jj,kk",mmm output : a,b,"ccddee",f,ii,"jjkk",mmm (3 Replies)
Discussion started by: mohan_tuty
3 Replies
Login or Register to Ask a Question