Sponsored Content
Full Discussion: Need some help with parsing
Top Forums Shell Programming and Scripting Need some help with parsing Post 302210231 by ghostdog74 on Monday 30th of June 2008 11:08:14 AM
Old 06-30-2008
just one way without regexp. though, using regexp , you can set multiline pattern matching and non greediness.
Code:
awk 'BEGIN{ORS=""}{ s=s$0}
END {
 n=index(s,"<Msg>" )
 while ( n > 0 ) {   
   m=index(s,"</Msg>" )   
   str=substr(s, n+5,m)  
   printf "%s\n",str
   s=substr(s,length(str)+1 ) 
   n=index(s,"<Msg>")
 }
}
' file

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

parsing

Hi, I want to parse this file.... ( 0 , 0 ) =>heading1 ( 0 , 1 ) =>value1.1a ( 0 , 2 ) =>value2.1a ( 1 , 0 ) =>heading2 ( 1 , 1 ) =>value1.1b ( 1 , 2 ) =>value2.1b ( 2 , 0 ) =>heading3 ( 2 , 1 ) =>value1.1c ( 2 , 2 ) =>value2.1c ( 3 , 0 ) =>heading4 ( 3 , 1 ) =>value1.1d ( 3 , 2... (15 Replies)
Discussion started by: tungaw2004
15 Replies

2. Shell Programming and Scripting

Parsing Binary

I have a binary file a particular format. It contains the Length Bytes and the Type bytes i.e the first four bytes if the file indicate the length of the Type which is to follow. for eg, if the int value of the first four bytes is 80, then it means that the length of the following "Type" is 80.... (2 Replies)
Discussion started by: xgringo
2 Replies

3. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

4. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

5. Shell Programming and Scripting

iterative parsing

I have always struggled when parsing a file vertically vs. by line horizontally. Can't seem to get my head around the concept. Here again I need to convert vertical output to horizontal output. original output root@acuransx:bpplsched 2000-STAND3 -v -M acuransx -l <2>bpplsched: INITIATING:... (4 Replies)
Discussion started by: jouuu
4 Replies

6. Shell Programming and Scripting

Need help with parsing a file

I trying to get only the highest version of the file names from an file which has list of file names. EX: CATEGORYDISPLAY JSP.A-SRC_BLD;2.4 CATEGORYDISPLAY JSP.A-SRC_BLD;2.5 CATEGORYDISPLAY JSP.A-SRC_BLD;2.1 CATEGORYDISPLAY JSP.A-SRC_BLD;2.2 The Script should display only the highest... (7 Replies)
Discussion started by: rocker_me2002
7 Replies

7. Shell Programming and Scripting

Parsing through Awk

Hi All, I have an input file something like this: Line1 Line2 .... LineN Identifier ( Field1a, Field1b; Field2a, Field1b; Field3a, Field1b; ..... ) LineN+1 LineN+2 etc.. I basically need Field1a, Field2a, Field3a.... from the above file (6 Replies)
Discussion started by: tostay2003
6 Replies

8. Shell Programming and Scripting

sed (parsing value)

All, Can somebody provide me with some sed expertise on how to parse the following line. 27-MAR-2011 10:28:01 * (CONNECT_DATA=(SID=dmart)(CID=(PROGRAM=sqlplus)(HOST=mtasnprod1)(USER=mtasnord))) * (ADDRESS=(PROTOCOL=tcp)(HOST=10.197.7.47)(PORT=54881)) * establish * dmart * 0 I would like... (3 Replies)
Discussion started by: BeefStu
3 Replies

9. Shell Programming and Scripting

Parsing the file

Hi all, Could anyone help me out? My input file is like: M1SYSNPENGGQINDNINYSE21PTMLPENLSLSNYDMDSFLGQFPSDNNMQLPHSTYEQHLQGEQQNPTNPNYFPPEFDEN2VDW1QE2 output is: M1 M1SYSNPENGGQINDNINYSE2 M1SYSNPENGGQINDNINYSE21 SYSNPENGGQINDNINYSE2 SYSNPENGGQINDNINYSE21 ... (2 Replies)
Discussion started by: yinyuemi
2 Replies

10. Shell Programming and Scripting

parsing

Can some body show me a sed command to remove everyhing upto a '/' and leave the rest of the line. cat data.out This is the directory /tmp/xxx/yy.ksh I only want to get the fullpath name /tmp/xxx.yy.ksh Thanks in advance to all who answer. (3 Replies)
Discussion started by: BeefStu
3 Replies
bytes(3pm)						 Perl Programmers Reference Guide						bytes(3pm)

NAME
bytes - Perl pragma to force byte semantics rather than character semantics NOTICE
This pragma reflects early attempts to incorporate Unicode into perl and has since been superseded. It breaks encapsulation (i.e. it exposes the innards of how the perl executable currently happens to store a string), and use of this module for anything other than debugging purposes is strongly discouraged. If you feel that the functions here within might be useful for your application, this possibly indicates a mismatch between your mental model of Perl Unicode and the current reality. In that case, you may wish to read some of the perl Unicode documentation: perluniintro, perlunitut, perlunifaq and perlunicode. SYNOPSIS
use bytes; ... chr(...); # or bytes::chr ... index(...); # or bytes::index ... length(...); # or bytes::length ... ord(...); # or bytes::ord ... rindex(...); # or bytes::rindex ... substr(...); # or bytes::substr no bytes; DESCRIPTION
The "use bytes" pragma disables character semantics for the rest of the lexical scope in which it appears. "no bytes" can be used to reverse the effect of "use bytes" within the current lexical scope. Perl normally assumes character semantics in the presence of character data (i.e. data that has come from a source that has been marked as being of a particular character encoding). When "use bytes" is in effect, the encoding is temporarily ignored, and each string is treated as a series of bytes. As an example, when Perl sees "$x = chr(400)", it encodes the character in UTF-8 and stores it in $x. Then it is marked as character data, so, for instance, "length $x" returns 1. However, in the scope of the "bytes" pragma, $x is treated as a series of bytes - the bytes that make up the UTF8 encoding - and "length $x" returns 2: $x = chr(400); print "Length is ", length $x, " "; # "Length is 1" printf "Contents are %vd ", $x; # "Contents are 400" { use bytes; # or "require bytes; bytes::length()" print "Length is ", length $x, " "; # "Length is 2" printf "Contents are %vd ", $x; # "Contents are 198.144" } chr(), ord(), substr(), index() and rindex() behave similarly. For more on the implications and differences between character semantics and byte semantics, see perluniintro and perlunicode. LIMITATIONS
bytes::substr() does not work as an lvalue(). SEE ALSO
perluniintro, perlunicode, utf8 perl v5.16.2 2012-08-26 bytes(3pm)
All times are GMT -4. The time now is 05:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy