Sponsored Content
Top Forums Shell Programming and Scripting Help with XML tag value extraction based on matching condition Post 303000579 by RavinderSingh13 on Friday 14th of July 2017 02:15:21 PM
Old 07-14-2017
Quote:
Originally Posted by paul1234
Hi Ravinder ,
I had tried this already .The LocalId tag repeats in the file so I wanted to get the value of LocalId tag only if the Workspace value has the string "Contract Request".
Hello paul1234,

Apologies missed it, please write only code in the code tags and information out side of code tags like I am writing here as an example. Could you please try following and let me know if this helps.
Solution 1st:
Code:
awk '/<_LocalId>/{sub(/.[^>]*/,"");gsub(/>|<.*/,"");val=$0;next} /<Workspace>.*Contract Request/{print val;exit}'  Input_file

Solution 2nd:
Code:
awk -F'[><]' '/<_LocalId>/{val=$3;next} /<Workspace>.*Contract Request/{print val;exit}'   Input_file

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl regexp: matching the parent xml tag

Hi folks. I would like to remove the full parent (outer) xml tag from a file given a matching child (inner) tag, in a bash shell. To be more specific, this is what I have so far: $ cat myFile.xml <Sometag></Sometag> <Outer> <Inner>1</Inner> </Outer> <Outer> <stuff>alot</stuff> ... (3 Replies)
Discussion started by: BatManWSL
3 Replies

2. Shell Programming and Scripting

Remove lines from XML based on condition

Hi, I need to remove some lines from an XML file is the value within a tag is empty. Imagine this scenario, <acd><acdID>2</acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> I... (3 Replies)
Discussion started by: giles.cardew
3 Replies

3. Shell Programming and Scripting

extract xml tag based on condition

Hi All, I have a large xml file of invoices. The file looks like below: <INVOICES> <INVOICE> <NAME>Customer A</NAME> <INVOICE_NO>1234</INVOICE_NO> </INVOICE> <INVOICE> <NAME>Customer A</NAME> <INVOICE_NO>2345</INVOICE_NO> </INVOICE> <INVOICE> <NAME>Customer A</NAME>... (9 Replies)
Discussion started by: angshuman
9 Replies

4. Shell Programming and Scripting

Check the value in xml based on condition

Hi, I have a log file having n number of xml's like the one below. <uOStatus xmlns:env="http://abc.org/def/ghi/"... (3 Replies)
Discussion started by: Neethu
3 Replies

5. Shell Programming and Scripting

Convert tag based lines to xml format

Hi All, Can some one help me to convert this line of code to xml format. Thanks in advance, preethy. input: ... (2 Replies)
Discussion started by: preethy
2 Replies

6. Shell Programming and Scripting

Multi line extraction based on condition

Hi I have some data in a file as below ****************************** Class 1A Students absent are : 1. ABC 2. CDE 3. CPE ****************************** Class 2A Students absent are : ****************************** Class 3A Students absent are : (6 Replies)
Discussion started by: reldb
6 Replies

7. Shell Programming and Scripting

Help with XML tag value extraction based on condition

sample xml file part <?xml version="1.0" encoding="UTF-8"?><ContractWorkspace xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" _LoadId="export_AJ6iAFmh+pQHq1" xsi:noNamespaceSchemaLocation="ContractWorkspace.xsd"> <_LocalId>CW2218471</_LocalId> <Active>true</Active> ... (3 Replies)
Discussion started by: paul1234
3 Replies

8. Shell Programming and Scripting

Help with tag value extraction from xml file based on a matching condition

Hi , I have a situation where I need to search an xml file for the presence of a tag <FollowOnFrom> and also , presence of partial part of the following tag <ContractRequest _LoadId and if these 2 exist ,then extract the value from the following tag <_LocalId> which is "CW2094139". There... (2 Replies)
Discussion started by: paul1234
2 Replies

9. UNIX for Beginners Questions & Answers

Replacing tag based on condition

Hi All, I am having a file like below. The file will having information about the records.If you see the file the file is header and data. For example it have 1 men tag and the tag id will be come after headers. The change is I want to convert All pets tag from P to X. I did a sed like below... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

10. 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
LINTIAN-INFO(1) 					User Contributed Perl Documentation					   LINTIAN-INFO(1)

NAME
lintian-info - give detailed information about Lintian's error tags SYNOPSIS
lintian-info [log-file...] lintian-info --tags tag ... DESCRIPTION
The lintian-info command parses the output of the lintian command and gives verbose information about the listed Lintian error tags, parses a Lintian override file and gives verbose information about the tags included, or (if given the -t or --tags option) explains a given tag or tags. If no log-file is specified on the command line, this command expects its input on stdin. Thus, the output of lintian can either be piped through lintian-info or a log file produced by lintian can be processed with this command. (Note, though, that the lintian command has a command line option -i to display the same results as lintian-info, so you will not normally need to pipe the output of lintian into this command.) OPTIONS
-a, --annotate Read from standard input or any files specified on the command line and search the input for lines formatted like Lintian override entries. For each one that was found, display verbose information about that tag. -h, --help Display usage information and exit. --profile prof Use the severities from the vendor profile prof when displaying tags. If the profile name does not contain a slash, the default profile for than vendor is chosen. If not specified, lintian-info loads the best profile for the current vendor. Please Refer to the Lintian User Manual for the full documentation of profiles. -t, --tags Rather than treating them as log file names, treat any command-line options as tag names and display the descriptions of each tag. EXIT STATUS
If -t or --tags was given and one or more of the tags specified were unknown, this command returns the exit code 1. Otherwise, it always returns with exit code 0. SEE ALSO
lintian(1) AUTHORS
Niels Thykier <niels@thykier.net> Richard Braakman <dark@xs4all.nl> Christian Schwarz <schwarz@monet.m.isar.de> perl v5.14.2 2013-02-16 LINTIAN-INFO(1)
All times are GMT -4. The time now is 04:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy