get text between two special rows ?(awk or sed)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get text between two special rows ?(awk or sed)?
# 8  
Old 12-06-2007
Hm ..., perhaps I've missed something,
not elegant solution Smilie:

Code:
awk '/^---/{c++}/constant/{c=0}/constant/,c==2' filename

# 9  
Old 12-06-2007
Quote:
Originally Posted by radoulov
Hm ..., perhaps I've missed something,
not elegant solution Smilie:

Code:
awk '/^---/{c++}/constant/{c=0}/constant/,c==2' filename

good idea, radoulov - nice!
# 10  
Old 12-06-2007
Code:
awk '{ if ( $0 ~ "constant string" ) { find=1; getline tmp; print  } if ( find && tmp !~ $0 ) { print tmp; last } }' filename

# 11  
Old 12-06-2007
Modified a bit:

Code:
awk '/^---/{c++}/constant/{c=0}!c,c==2' c=1  filename

# 12  
Old 12-07-2007
Java

Thanks a lot to all,

I believe that awk seemed to be very powerful and complex.
So I've searched for further informations:
[Chapter 7] 7.3 Awk's Programming Model

When I've understood your examples, especialy from radoulov I will be able to solve my problem

Thanks and best regards,
Eric
# 13  
Old 12-07-2007
Hy radoulov,

you script works very fine, but what does

!c,c==2

do?

thanks, Eric
# 14  
Old 12-07-2007
In Awk:

Quote:
pat1, pat2

A pair of patterns separated by a comma, specifying a range of records.
Print the records from the one where c is not true (!c): c equals 0 (the records with your constant string, because of this code:

Code:
/constant/{c=0}

), to where c equals 2.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk or sed? rows text to co

Hello Friends! I would like to help the masters ... I have a file with the entry below and would like a script for that output: Input file: 001 1 01-20152142711532-24S 1637909825/05/2015BAHIA SERVICOS R F, ... (1 Reply)
Discussion started by: He2
1 Replies

2. Shell Programming and Scripting

Indexing each repeating pattern of rows in a column using awk/sed

Hello All, I have data like this in a column. 0 1 2 3 0 3 4 5 6 0 1 2 3 etc. where 0 identifies the start of a pattern in my data. So I need the output like below using either awk/sed. 0 1 (2 Replies)
Discussion started by: ks_reddy
2 Replies

3. Shell Programming and Scripting

Sed or awk : pattern selection based on special characters

Hello All, I am here again scratching my head on pattern selection with special characters. I have a large file having around 200 entries and i have to select a single line based on a pattern. I am able to do that: Code: cat mytest.txt | awk -F: '/myregex/ { print $2}' ... (6 Replies)
Discussion started by: usha rao
6 Replies

4. Shell Programming and Scripting

Using sed (or awk or perl) to delete rows in a file

I have a Unix file with 200,000 records, and need to remove all records from the file that have the character I' in position 68 (68 bytes from the left). I have searched for similar problems and it appears that it would be possible with sed, awk or perl but I do not know enough about any of these... (7 Replies)
Discussion started by: joddo
7 Replies

5. AIX

Rows manupulation using AWK or sed

Hi Everyon, I am stuck in a script.I have a file named file1.txt as given below: It contains 2 columns-count and filename. cat file1.txt count filename 100 A_new.txt 1000 A_full.txt 1100 B_new.txt 2000 B_full.txt 1100 C_new.txt 2000 C_full.txt ................... ..................... (10 Replies)
Discussion started by: rajsharma
10 Replies

6. Shell Programming and Scripting

sed usage with special characters - text manipulation

I'm trying to use sed to replace string in text file but I've some problems with slash and new-line for example I have to replace this string: \> signal_rssi=" or this string where new-line is in the middle of the string: " /> I'm using this code for the first case but it doesn't... (10 Replies)
Discussion started by: TheMrOrange
10 Replies

7. Shell Programming and Scripting

Special Character SED/AWK removal

I have a script that produces an output containing '/.ssh'. I am trying to find a way of parsing only this data from a single line, without removing any other special characters contained within the output as a result of the parse. Any help would be appreciated (6 Replies)
Discussion started by: Raggedranger333
6 Replies

8. Shell Programming and Scripting

Get text between two special rows ?( using awk or sed)?

Hi Friends I am facing some problem in extract the lines between two fixed lines for examplemy text file look like ... -------- line 1 line 2 line 3 --------- line 4 line 5 -------- line 6 line 7 line 8 line 9 line 10 --------- now i want the data between "-------" these... (4 Replies)
Discussion started by: sushantnirwan
4 Replies

9. Shell Programming and Scripting

sed or awk to convert text files with recurring headings to rows and colum

I have many text file reports generated by a Information Assurance tool that I need to get into a .CSV format or Excel tab delimited format. I want to use sed or awk to grab all the information in the sample text file below and create column headings:Risk ID, Risk Level, Category, Description, How... (5 Replies)
Discussion started by: Bjoeboo
5 Replies

10. Shell Programming and Scripting

awk/sed with special characters

i have this script that searches for a pattern. However it fails if the pattern includes some special characters. So far, it fails with the following strings: 1. -Cr 2. $Mj 3. H'412 would a sed or awk be more effective? i don't want the users to put the (\) during the search (they... (5 Replies)
Discussion started by: apalex
5 Replies
Login or Register to Ask a Question