awk, sed or perl regexp to print values from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk, sed or perl regexp to print values from file
# 1  
Old 04-17-2012
awk, sed or perl regexp to print values from file

Hello all

According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values

Code:
example, running this script/command like
./script.sh xxapp
I would expect as output: 102 116 112

./script.sh xxapp2
will print: 114 118



Code:
  <?xml version="1.0" encoding="UTF-8"?>
  <XmlProfile>
   <be.netbase.securitydaemon.xml.XmlProfile>
    <children length="480">
     <be.netbase.securitydaemon.xml.XmlProfile>
      <name><![CDATA[xxapp]]></name>
      <properties>
       <pair>
       ....
       </pair>
       <pair>
       ....
       </pair>
       <pair>
        <java.lang.String><![CDATA[userpassword]]></java.lang.String>
        <java.lang.reflect.Array dim="1" length="1" type="java.lang.Object">
         <java.lang.reflect.Array dim="1" type="byte">
          <byte><![CDATA[102]]></byte>
          <byte><![CDATA[116]]></byte>
          <byte><![CDATA[112]]></byte>
         </java.lang.reflect.Array>
        </java.lang.reflect.Array>
       </pair>
      </properties>
     </be.netbase.securitydaemon.xml.XmlProfile>
     <be.netbase.securitydaemon.xml.XmlProfile>
      <name><![CDATA[xxapp2]]></name>
      <properties>
      ...
        <java.lang.String><![CDATA[userpassword]]></java.lang.String>
        <java.lang.reflect.Array dim="1" length="1" type="java.lang.Object">
         <java.lang.reflect.Array dim="1" type="byte">
          <byte><![CDATA[114]]></byte>
          <byte><![CDATA[118]]></byte>
         </java.lang.reflect.Array>
        </java.lang.reflect.Array>
        <pair>
        ....
        </pair>
       ....
      </be.netbase.securitydaemon.xml.XmlProfile>
    ...
    etc...

Thanks in advance for your attention

Cheers Smilie
# 2  
Old 04-17-2012
Try:
Code:
awk -F'[]]|CDATA[[]' '/<name>/{c=$2} c==n && /<byte>/{print $2}' n=xxapp2 infile

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 04-17-2012
This is great Scrutinizer, thank you again for your precious help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk or sed to print the character from the previous line after the regexp match

Hi All, I need to print the characters in the previous line just before the regular expression match Please have a look at the input file as attached I need to match the regular expression ^ with the character of the previous like and also the pin numbers and the output file should be like... (6 Replies)
Discussion started by: kshitij
6 Replies

2. Shell Programming and Scripting

awk to print line is values between two fields in separate file

I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

awk regexp to print repetitive pattern

How to use regexp to print out repetitive pattern in awk? $ awk '{print $0, "-\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-"}' output: - - - - - - - - - - - -I tried following which does not give what I want, of course. awk '{print $0, "-\t{11}-"}' output: - ... (10 Replies)
Discussion started by: yifangt
10 Replies

4. Shell Programming and Scripting

sed print first line before regexp and all lines after

Hi All I'm trying to extract the line just above a regexp and all lines after this. I'm currently doing this in two steps sed -n -e "/^+---/{g;p;}" -e h oldfile.txt > modified.txt sed -e "1,/^+---/d" -e "/^$/d" oldfile.txt >>modified.txt Sample sometext will be here sometext will be... (3 Replies)
Discussion started by: Celvin VK
3 Replies

5. UNIX for Advanced & Expert Users

Awk to print values of second file

Hello, I have a data file with 300,000 records in it, and another file which contains only the line numbers of roughly 13,000 records in the data file which have data integrity issues. I'm trying to find a way to print the original data by line number identified in the second file. How can I do... (2 Replies)
Discussion started by: peteroc
2 Replies

6. Shell Programming and Scripting

replace awk with a perl one liner (REGEXP and FS)

hello, I want to replace awk with a perl one liner in unix. i use in awk REGEX and FS ( field separator) because awk syntaxes in different unix os versions have not the same behaviour. Awk, Nawk and GNU Awk Cheat Sheet - good coders code, great reuse i have a file named "file" and want... (5 Replies)
Discussion started by: bora99
5 Replies

7. Shell Programming and Scripting

Print required values at end of the file by using AWK

I am looking help in awk, quick overview. we will get feed from external system . The input file looks like below. Detail Id Info Id Order Id STATUS Status Date FileDetail 99127942 819718 CMOG223481502 PR 04-17-2011 06:01:34PM... (7 Replies)
Discussion started by: dvrbabu
7 Replies

8. Shell Programming and Scripting

...yet another string of awk/sed questions from a RegExp-Challenged luser %-\

Greetings all, ...here is yet another string of awk/sed questions from a RegExp-Challenged luser :eek: I'm looking to have sed/awk do some clean-up on routing tables and to that end, I would like to do the following: 1.) If a line contains the word "masks" or "subnets" prepend CR/LF to... (16 Replies)
Discussion started by: SteveB-in-LV
16 Replies

9. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

10. UNIX for Dummies Questions & Answers

using awk or sed to print output from one file

dear i have one file regarding >abshabja>sdksjbs>sknakna>snajxcls so i want to be output like >abshabja >sjkabjb >sknakna >snajxcls Any using awk or sed will help thanks (2 Replies)
Discussion started by: cdfd123
2 Replies
Login or Register to Ask a Question