Easy way to pull a paragraph from a text file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Easy way to pull a paragraph from a text file?
# 1  
Old 01-30-2011
Easy way to pull a paragraph from a text file?

I have a collection of text files that comprise a mailing list archive. I grep them to find an email that interests me, then open the file in a text editor to find the surrounding paragraph of text. Is there an easy way to do this from the shell instead?
# 2  
Old 01-30-2011
If you want context around the line use the -A, -B, or -C options. For instance:

Code:
grep "string" /path_to_directory/ -C50

This will give you 50 lines of context around the line matched. Also, I like to use the --color=always option which gives me the lined matched in color red for easy identification.
# 3  
Old 01-30-2011
Excellent, thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print each paragraph in a text file into excel file

Hi, I have a below text file, which needs to be printed into attached excel file. Please help me. Thanks (4 Replies)
Discussion started by: prash358
4 Replies

2. Shell Programming and Scripting

Script to pull hashes out of large text file

I am attempting to write a script that will pull out NTLM hashes from a text file that contains about 500,000 lines of data. Not all accounts contain hashes and I only need the ones that do contain hashes. Here is a sample of what the data looks like: There are thousands of other lines in... (6 Replies)
Discussion started by: chango77747
6 Replies

3. UNIX for Dummies Questions & Answers

Output text from 1st paragraph in file w/ a specific string through last paragraph of file w/ string

Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string. Previously, I was outputting just each paragraph with that search string with: cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Discussion started by: carpenn
2 Replies

4. Shell Programming and Scripting

grabbing filename from text file....should be easy!

Quick question...I'm trying to grab the .tif file name from this output from our fax server. What is the best way i can do this in a bash script? I have been looking at regular expressions with bash or using awk but having some trouble. thanks! The only output i want is... (5 Replies)
Discussion started by: kuliksco
5 Replies

5. Shell Programming and Scripting

Search for a particular string in a paragraph in a text

Hi all, i'm new to this community. I am trying to write a script which will fetch ftp completion time of a file from a paragraph of a big text file ( which contains multiple paragraphs) . Each paragraph will have ftp details.. Now I dont know how to fetch process time within a paragraph of... (3 Replies)
Discussion started by: prachiagra
3 Replies

6. Shell Programming and Scripting

Pull specific data from repetitive text?

Hi all, I have a bit of a problem with a loop that extracts repetitive text. Running /bin/index executable outputs this text to terminal: testing index 'scanthread'... collected 0 docs, 0.0 MB total 0 docs, 0 bytes total 0.012 sec, 0 bytes/sec, 0.00 docs/sec testing index 'scanpost'...... (6 Replies)
Discussion started by: TECK
6 Replies

7. Shell Programming and Scripting

convert text contents/paragraph to cvs

hi all, iam new to awk & sed cmd and appreacite help from all the script expert from this forum, i have a file like below: Fri Aug 01 00:01:19 2008 NAS-IP-Address = 172.16.160.1 Class = "P1-SHT-AAA01;1217116976;70999" Calling-Station-Id = "00-11-FB-01-03-06" Acct-Status-Type = Start... (13 Replies)
Discussion started by: xajax7
13 Replies

8. UNIX for Dummies Questions & Answers

Need help on installing an EASY to use and easy to install command line text editor

Hi again. Sorry if it seems like I'm spamming the boards a bit, but I figured I might as well ask all the questions I need answers to at once, and hopefully at least get some. I have installed Solaris 10 on a server. The default text editors are there (vi, ex, ed, maybe others, I know emacs is... (4 Replies)
Discussion started by: EugeneG
4 Replies

9. Shell Programming and Scripting

extracting last paragraph from a text

Hi All, I want to extract last paragraph from a text for example aaaaa sadafsa sdfdsaf asfdsad asfdsfad asfdfsafd adfssas asdfsafdsa asfdasdfa sadfasdsaf i need the last paragraph how to do it using linux commands (1 Reply)
Discussion started by: uvrakesh
1 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question