Display records between two search strings using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display records between two search strings using sed
# 1  
Old 07-20-2012
Display records between two search strings using sed

I have input file like
Code:
AAA
AAA
CCC
CCC
CCC
EEE
EEE
EEE
EEE
FFF
FFF
GGG
GGG

i was trying to retrieve data between two strings using sed.
Code:
sed -n /CCC/,/FFF/p input_file

Am getting output like
Code:
CCC
CCC
CCC
EEE
EEE
EEE
EEE
FFF

The above command retrieves the data till to the first occurence of the destination string (i.e., till 1st occurence off FFF record)
I need to search the records till last occurence.
Expected output is
Code:
CCC
CCC
CCC
EEE
EEE
EEE
EEE
FFF
FFF

Plz help on this query.

Last edited by Scrutinizer; 07-20-2012 at 08:32 AM.. Reason: code tags
# 2  
Old 07-20-2012
DO NOT POST DUPLICATE POSTS!!!

I could see the same HERE...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to search and lossless replace strings using sed?

Hello, I would like to replace all occurencies of long data types by others (coresponding int) using 'sed' in the extensive source code of a software package written for 32 bit CPUs. I must use regular expressions to avoid wrong replacements like s/unsigned]+long/ulong/gLeaving out... (2 Replies)
Discussion started by: Mick P. F.
2 Replies

2. Shell Programming and Scripting

Search strings and highlight them using Perl or bash/awk/sed

Hi, I have two files: a.doc and b.txt I wish to search the strings from file b.txt in a.doc and want to highlight them in a.doc with different colours using Perl or bash./awk/sed? Please guide me. :) Thanks!!!!! (10 Replies)
Discussion started by: bioinfo
10 Replies

3. Shell Programming and Scripting

Search between two search strings and print the value

Based on the forums i have tried with grep command but i am unable to get the required output. search this value /*------ If that is found then search for temp_vul and print and also search until /*------- and print new_vul Input file contains: ... (5 Replies)
Discussion started by: onesuri
5 Replies

4. Shell Programming and Scripting

Display all lines after and before two different strings

Hi, What is the easiest way to display set of lines after a search string (x) and before search (y) . The grep -A -B doesn't seem to be helpful in this case. Any ideas.. -Kevin (2 Replies)
Discussion started by: Kevin Tivoli
2 Replies

5. Shell Programming and Scripting

Get records that does not contain particular strings

Hi, I know grep, but I could not get the following using grep. I'm little bit weak in AWK. I have a file with numeric, alphabets( or ) with semicolon ";" as separator. How do I get the record that may have bad characters/String along with good characters/String Eg. File1.txt =======... (1 Reply)
Discussion started by: bobbygsk
1 Replies

6. Shell Programming and Scripting

Help with sed search&replace between two strings

Hi, i read couple of threads here on forum, and googled about what bugs me, yet i still can't find solution. Problem is below. I need to change this string (with sed if it is possible): This is message text that is being quoted to look like this: This is message text that is being quotedI... (2 Replies)
Discussion started by: angrybb
2 Replies

7. Shell Programming and Scripting

deleting text records with sed (sed paragraphs)

Hi all, First off, Thank you all for the knowledge I have gleaned from this site! Deleting Records from a text file... sed paragraphs The following code works nearly perfect, however each time it is run on the log file it adds a newline at the head of the file, run it 5 times, it'll have 5... (1 Reply)
Discussion started by: Festus Hagen
1 Replies

8. Shell Programming and Scripting

sed search/replace and display

Hi All: I'm using sed to replace one line in a configuration file. After replacing that line I would like to display to screen that line plus 10 lines above and below the line that was changed... How would I go about doing that?? Here is my search and replace string.... sed -e... (2 Replies)
Discussion started by: jimmyc
2 Replies

9. Shell Programming and Scripting

how to display records of file

dear all, supose there is file called myfile.txt and in this file there are two records.. like this way:- myfile.txt records 1 A:B:C:D:E records 2 B:C:A:F:G I have to find A and display output as "in myfile.txt in record1 A has feild 1 and in myfile.txt in record2 A... (2 Replies)
Discussion started by: mishra_sk_in
2 Replies

10. UNIX for Dummies Questions & Answers

using cat and grep to display missing records

Gentle Unix users, Can someone tell me how I can use a combination of the cat and grep command to display records that are in FileA but missing in FileB. cat FileA one line at a time and grep to see if it is in fileB. If it is ignore. If line is not in fileB display the line. Thanks in... (4 Replies)
Discussion started by: jxh461
4 Replies
Login or Register to Ask a Question