sed problem - delete all lines until a match on 2 lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed problem - delete all lines until a match on 2 lines
# 8  
Old 09-17-2009
Hi Franklin,

Thank you. But i cant understand the procedure how this command gives the output Smilie.

once the string "STARTUP NOMOUNT" matches from the input file i value will get increased to 1. After that how its printing the next lines upto the next match.

That is how this command prints the 2,3 lines also in file_1 file(output file)
Please explain

Example for the input file:
-------------------------
STARTUP NOMOUNT
test_file
text
STARTUP NOMOUNT

Thanks in advance,
# 9  
Old 09-17-2009
Quote:
Originally Posted by puni
Hi Franklin,

Thank you. But i cant understand the procedure how this command gives the output Smilie.

once the string "STARTUP NOMOUNT" matches from the input file i value will get increased to 1. After that how its printing the next lines upto the next match.

That is how this command prints the 2,3 lines also in file_1 file(output file)
Please explain

Example for the input file:
-------------------------
STARTUP NOMOUNT
test_file
text
STARTUP NOMOUNT

Thanks in advance,
It's quite simple, maybe this is more understandable:

Code:
/STARTUP NOMOUNT/{i++} # If the line matches the pattern then i = i + 1

Code:
i{print > "file_" i} # If i is not 0 print the line to the file "file_i"

After the first match the lines are printed to the file file_1 (i == 1), after the second match (i == 2) the lines are printed to the file file_2 (i == 2) etc.


Regards
# 10  
Old 09-17-2009
resetting the value of "i" to zero(0) did not happen... that is why it prints all the lines between regular expression...
# 11  
Old 09-18-2009
Hi thank a lot folks, now i understood
# 12  
Old 09-18-2009
thank you all for the valuable help
know_d_unknown, you proved my case that this is feasable with sed (so, I won 12 beers from one of my colleaugues :-) )
but I also agree that the solution of franklin is the best one
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete lines based on pattern match

BASH in Solaris 10 I have a log file like below. Whenever the pattern ORA-39083 is encountered, I want to delete the line which has this pattern and 3 lines below it. $ cat someLogfile.txt ORA-39083: Object type OBJECT_GRANT failed to create with error: ORA-01917: user or role 'CMPA' does... (4 Replies)
Discussion started by: kraljic
4 Replies

2. Shell Programming and Scripting

sed read X lines after match

I want to do something like sed -n '/PATTERN/,+10p' and get the ten lines following PATTERN. However, this throws an "expected context address" with the sed that comes with OSX Lion. If that + is a GNUism, can I do this, or do I have to find another tool? (2 Replies)
Discussion started by: jnojr
2 Replies

3. UNIX for Dummies Questions & Answers

sed, join lines that do not match pattern

Hello, Could someone help me with sed. I have searched for solution 5 days allready :wall:, but cant find. Unfortunately my "sed" knowledge not good enough to manage it. I have the text: 123, foo1, bar1, short text1, dat1e, stable_pattern 124, foo2, bar2, long text with few lines, date,... (4 Replies)
Discussion started by: petrasl
4 Replies

4. Shell Programming and Scripting

Sed delete blank lines upto first pattern match

Hi Im trying to do the following in sed. I want to delete any blank line at the start of a file until it matches a pattern and then stops. for example: Input output: I have got it to work within a range of two patterns with the following: sed '/1/,/pattern/{/^]*$/d}' The... (2 Replies)
Discussion started by: duonut
2 Replies

5. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

6. Shell Programming and Scripting

Delete lines line by match data 2 file.

i need to delete the lines is match from file data 1 & data 2 please help? data 1 4825307 4825308 4825248 4825309 4825310 4825311 4825336 data 2 4825248 0100362210 Time4Meal 39.00 41.73 MO & MT MT SMS 4825305 0100367565... (2 Replies)
Discussion started by: ooilinlove
2 Replies

7. Shell Programming and Scripting

delete block of lines when pattern does not match

I have this input file that I need to remove lines which represents more than 30 days of processing. Input file: On 11/17/2009 at 12:30:00, Program started processing...argc=7 Total number of bytes in file being processed is 390 Message buffer of length=390 was allocated successfully... (1 Reply)
Discussion started by: udelalv
1 Replies

8. Shell Programming and Scripting

sed print all lines after pattern match

HiCan someone show me how to print all lines from a file after a line matching a pattern using sed?Thanks (13 Replies)
Discussion started by: steadyonabix
13 Replies

9. Shell Programming and Scripting

SED: match pattern & delete matched lines

Hi all, I have the following data in a file x.csv: > ,this is some text here > ,,,,,,,,,,,,,,,,2006/11/16,0.23 > ,,,,,,,,,,,,,,,,2006/12/16,0.88 < ,,,,,,,,,,,,,,,,this shouldnt be deleted I need to use SED to match anything with a > in the line and delete that line, can someone help... (7 Replies)
Discussion started by: not4google
7 Replies

10. UNIX for Dummies Questions & Answers

How to delete lines do NOT match a pattern

On Unix, it is easy to get those lines that match a pattern, by grep pattern file or those lines that do not, by grep -v pattern file but I am editing a file on Windows with Ultraedit. Ultraedit support regular expression based search and replace. I can delete all the lines that match a... (1 Reply)
Discussion started by: JumboGeng
1 Replies
Login or Register to Ask a Question