Pulling multiple lines of text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pulling multiple lines of text
# 1  
Old 03-10-2008
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 Smilie )

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  
Old 03-10-2008
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  
Old 03-10-2008
here's a simular way to do also:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join multiple lines from text file

Hi Guys, Could you please advise how to join multiple details lines into single row, with HEADER 1 as the record separator and comma(,) as the field separator. Input: HEADER 1, HEADER 2, HEADER 3, 11,22,33, COLUMN1,COLUMN2,COLUMN3, AA1, BB1, CC1, END: ABC HEADER 1, HEADER 2,... (3 Replies)
Discussion started by: budz26
3 Replies

2. Shell Programming and Scripting

Process multiple lines in a text file

Hi All I have text file like this: a=21ej c=3tiu32 e=hydkehw f=hgdiuw g=jhdkj a=klkjhvl b=dlkjhyfd a=yo c=8732 Any way I can process data from first a to just before of second a, and then second a to just before of 3rd one. Just fetching records like that will help, I mean... (3 Replies)
Discussion started by: sandipjee
3 Replies

3. Shell Programming and Scripting

Extracting Multiple Lines from a Text File

Hello. I am sorry if this is a common question but through all my searching, I haven't found an answer which matches what I want to do. I am looking for a sed command that will parse through a large text file and extract lines that start with specific words (which are repeated throughout the... (4 Replies)
Discussion started by: MrDumbQuestion
4 Replies

4. Shell Programming and Scripting

Pulling x number of lines from one file and save into another

Hi, I have a log file (updates.log), and I want to hunt the file for any errors. Here's an example of the log file: SQL> update <table1> set <value1> = '*****'; update <table1> set <value1> = '*****' * ERROR at line 1: ORA-00942: table or view does not exist Elapsed:... (4 Replies)
Discussion started by: dbchud
4 Replies

5. UNIX for Dummies Questions & Answers

How to generate multiple lines in a text file?

Hello, I want to create a file whose content is multiple lines of strings. The string has the following pattern: aaaa/bbbb/A-B.txt A is a variable ranges from A1 to A2 B is a variable ranges from B1 to B2 Any ideas? Thanks. (17 Replies)
Discussion started by: vic005
17 Replies

6. UNIX for Dummies Questions & Answers

Help please, extract multiple lines from a text file

Hi all, I need to extract lines between the lines 'RD' and 'QA' from a text file (following). there are more that one of such pattern in the file and I need to extract all of them. however, the number of lines between them is varied in the file. Therefore, I can not just use 'grep -A' command.... (6 Replies)
Discussion started by: johnshembb
6 Replies

7. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

8. UNIX for Dummies Questions & Answers

removing multiple lines of text in a file

Hi, I'm trying to remove multiple lines of text based off a series of different words and output it to a new file The document contains a ton of data but i want to delete any line that has the following mx1.rr.biz.com or ns2.ri.biz.com i tried using grep -v filename "mx1.rr.biz.com" >... (3 Replies)
Discussion started by: spartan22
3 Replies

9. Shell Programming and Scripting

deleting lines from multiple text files

I have a directory full of text data files. Unfortunately I need to get rid of the 7th and 8th line from them all so that I can input them into a GIS application. I've used an awk script to do one at a time but due to the sheer number of files I need some kind of loop mechanism to automate... (3 Replies)
Discussion started by: vrms
3 Replies

10. Shell Programming and Scripting

Pulling data and following lines from file

I saw a few posts close to what i want to do, but they didn't look like they would work exactly.. or I need to think out of the box on this. I have a file that I keep server stats in for my own performance analysis. this file has the output from many commands in it (uptime, vmstats, ps, swap... (2 Replies)
Discussion started by: MizzGail
2 Replies
Login or Register to Ask a Question