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
sed selective data parsing dunstonrocks Shell Programming and Scripting 1 03-29-2009 07:00 AM
Another data extraction question kunigirib Shell Programming and Scripting 6 12-24-2008 06:36 PM
Data Extraction From a File rrangaraju Shell Programming and Scripting 3 12-23-2008 04:26 PM
help with data extraction script mam Shell Programming and Scripting 11 01-16-2008 06:50 AM
Data Extraction issue. irehman Shell Programming and Scripting 5 04-06-2006 09:28 AM

Reply
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 06-26-2009
dwgi32 dwgi32 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 22
Selective extraction of data from a files

Hi,

I would like to seek for methods to do selective extraction of line froma file. The scenario as follows:

I have a file with content:

[RECV]
message a
received on 11:10:00
file size: 10 bytes
send by abc
[End]

[RECV]
message b
received on 11:20:00
file size: 10 bytes
send by abc
[End]

[RECV]
message c
received on 11:30:00
file size: 10 bytes
send by abc
message d
received on 11:40:00
file size: 10 bytes
send by abc
[End]

I will like to extract the last [RECV] portion from the file i.e message c and d. The [RECV] and [End] is fixed but the number of message in each portion is not fixed.

Thank for the advice.

Cheer
  #2 (permalink)  
Old 06-26-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,558
GNU awk

Code:
#awk 'BEGIN{RS=""}END{print }' file

try to produce some code next time before you ask questions.
  #3 (permalink)  
Old 06-26-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,098

Code:
local $/="[End]\n\n";
my $tmp;
while(<DATA>){
	$tmp=$_;
}
print $tmp;
__DATA__
[RECV]
message a
received on 11:10:00
file size: 10 bytes
send by abc
[End]

[RECV]
message b
received on 11:20:00
file size: 10 bytes
send by abc
[End]

[RECV]
message c
received on 11:30:00
file size: 10 bytes
send by abc
message d
received on 11:40:00
file size: 10 bytes
send by abc
[End]

  #4 (permalink)  
Old 06-26-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,133

Code:
grep -p 'message c' file

Reply

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 04:51 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