The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting records with unique fields from a fixed width txt file sitney Shell Programming and Scripting 8 02-10-2008 03:18 AM
extracting fields prvnrk Shell Programming and Scripting 2 10-08-2007 04:39 AM
Extracting information from text fields. spindoctor UNIX for Dummies Questions & Answers 24 06-09-2007 02:17 PM
Removing certain fields from a file sendhilmani123 Shell Programming and Scripting 1 05-02-2006 03:01 AM
Extracting fields from an output 8-) csaha Shell Programming and Scripting 6 01-20-2006 08:37 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-22-2008
gugs gugs is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 44
Removing LF and extracting two fields

I need some assistance, I am writing a script in bash.

I want to do two things:
1/. I want to replace the LF at the end of the RFH  Ĝ  ¸MQSTR ¸ so I can process the file record by record using a while loop.

2/. I want to extract two fields from each record, they are identified with tabs <RequestID></RequestID> and <error:Info></error:Info> from the sample data below.

In my file as shown below, each record in the file starts with: RFH  Ĝ  ¸MQSTR ¸ followed LF followed by the data:

RFH  Ĝ  ¸MQSTR ¸
<usr><SourceID>SYSA</SourceID><DSType>SPIResults</DSType><Source>SYSA</Source><Destina
tion>PortalSystem</Destination><RequestID>1000005</RequestID><TargetTablePrimaryKey>5</
TargetTablePrimaryKey><Replay><Original/><Current><DestinationSystemID>SYSA</DestinationSy
stemID></Current></Replay><TargetURI>SYSB</TargetURI><DestinationID>SYSA<
/DestinationID></usr> <mcd><Msd>xmlns</Msd></mcd> <?xml version="1.0"
encoding="UTF-8"?><error:Code>001</error:Code><error:Info>An error occured whilst trying
to process a routing request, see attached exception lists for
details</error:Info><error:OriginalExceptionData></mm:MessageMetadata><mf:MessageFormat SchemaVersion="1.0"><mf:MessageType><msg:Type>SPIResults</msg:Type><msg:Version>1.200</msg:Version>
RFH  Ĝ  ¸MQSTR ¸
<usr><SourceID>SYSA</SourceID><DSType>SPIResults</DSType><Source>SYSA</Source><Destina
tion>PortalSystem</Destination><RequestID>1000005</RequestID><TargetTablePrimaryKey>5</
TargetTablePrimaryKey><Replay><Original/><Current><DestinationSystemID>SYSA</DestinationSy
stemID></Current></Replay><TargetURI>SYSB</TargetURI><DestinationID>SYSA<
/DestinationID></usr> <mcd><Msd>xmlns</Msd></mcd> <?xml version="1.0"
encoding="UTF-8"?><error:Info>An error occured whilst trying to process a routing request,
see attached exception lists for details</error:Info><error:OriginalExceptionData>
RFH  Ĝ  ¸MQSTR ¸
<usr><SourceID>SYSA</SourceID><DSType>SPIResults</DSType><Source>SYSA</Source><Destina
tion>PortalSystem</Destination><RequestID>1000005</RequestID><TargetTablePrimaryKey>5</
TargetTablePrimaryKey><Replay><Original/><Current><DestinationSystemID>SYSA</DestinationSy
stemID></Current></Replay><TargetURI>SYSB</TargetURI><DestinationID>SYSA<
/DestinationID></usr> <mcd><Msd>xmlns</Msd></mcd> <?xml version="1.0"
encoding="UTF-8"?><error:Info>An error occured whilst trying to process a routing request,
see attached exception lists for details</error:Info></mm:MessageMetadata><mf:MessageFormat SchemaVersion="1.0"><mf:MessageType><msg:Type>SPIResults</msg:Type>
  #2 (permalink)  
Old 07-22-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,311
1st: Please use [ c o d e ] [ / c o d e ] tags!!

A bit lengthy, maybe someone comes up a shorter version:

Code:
cat infile |\
tr -d '\n' |\
sed 's/[^^]RFH/\nRFH/g' |\
sed 's!.*<RequestID>\([^<]*\)<\/RequestID>.*<error:Info>\([^<]*\)<\/error:Info>.*!\1 \2!g'

Both steps are combined. Not sure if you need to loop for the second step, if so, there is no need to loop, as sed take a stream and checks every single line of input. If you only want step 1 though, just stop after the 1st line of sed ie. redirect it to a new file or whatever.

Last edited by zaxxon; 07-22-2008 at 10:38 AM.. Reason: Adding notice to use code tags
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0