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
deleting lines from multiple text files vrms Shell Programming and Scripting 3 04-25-2008 12:01 PM
retrieved multiple lines on multiple places in a file dala Shell Programming and Scripting 8 03-14-2008 03:28 PM
How to delete first 5 lines and last five lines in all text files ragavendran31 Shell Programming and Scripting 10 02-21-2008 07:58 AM
Pulling data and following lines from file MizzGail Shell Programming and Scripting 2 01-31-2006 03:13 PM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 03:50 PM

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 03-10-2008
DumDum DumDum is offline
Registered User
  
 

Join Date: Apr 2002
Location: Oakland, CA
Posts: 4
Pulling multiple lines of text

Hello,

So, I'm not even sure if this will be possible for me to do (then again, that's why I'm asking for help )

What I'm trying to do is pull multiple lines out of a very large text file, separating them into smaller files. Basically it's a text archive of a few hundred emails.

What I have to work with is I do have a constant start line and end line. What I've been doing so far is to grep for the start of a message (grepping for '^From:' While this will pull the one line I am unsure as to how I can then get the next x number of lines to record into some sort of new text file and then stop at the known end line. (at the moment it's 30 '+' symbols...I don't know why, that's how it came)

I'm thinking grep probably won't do all I want it to do. Should I be looking for something more along the lines of sed or awk?
  #2 (permalink)  
Old 03-10-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
Not sure how your file exactly looks like but the following awk command should be a good start.
It searches for a pattern and prints the lines until a line begins with "++++":


Code:
awk '
/^From:/{found=1}
found && $1 ~ /^++++/ {found=0}
found {print}' file


Regards
  #3 (permalink)  
Old 03-10-2008
timj123 timj123 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 80
here's a simular way to do also:


Code:
awk '
/^From:/ { f ; next }
f { print }
/+++$/ { f = "" ; next }' file

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 04:04 AM.


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