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)?
# 1  
Old 12-06-2007
get text between two special rows ?(awk or sed)?

Hello,

I've the follwing text:

gfdgfg
--------------------------------
dfgfdgdfg
fdgfdgfdgdgf
fdgf
------------------------------
f
g
gdgf
a constant string that i know
---------------------------------------------
data I want to have data I want to have
data I want to have data I want to have
....
data I want to have data I want to have
data I want to have data I want to have

----------------------------------------------
fdgfdg
fdgfdgd
fdgfdg
---------------------------------
dsfgfdgfdg
dsfgfdgfd
dfsg
-----------------------------------
sfdgfdgf
fdgfdg




I want to get the text between the rows ------------------------
Before this there is a known constant String.
I've tried with sed, but with no result. I've the problem that
there are mutiples textparts between the rows --------------------

Any ideas?

Thanks a lot,
Eric
# 2  
Old 12-06-2007
Code:
awk '/start_pattern/,/end_pattern/ { print }' filename

# 3  
Old 12-06-2007
pattern with mutiple rows possible?

Hy matrixmadhan,

is it with awk possible to create a pattern over 2 rows?

best regards, Eric
# 4  
Old 12-06-2007
Something like this:

Code:
awk '/^---/{f=0}/constant/{getline;f=1;next}f' filename

Use nawk or /usr/xpg4/bin/awk on Solaris.
# 5  
Old 12-06-2007
Quote:
Originally Posted by eric_
Hy matrixmadhan,

is it with awk possible to create a pattern over 2 rows?

best regards, Eric
can you post sample input and output ?
# 6  
Old 12-06-2007
Hy,

Input is like the my first post and output should be only the bold text.
or in ohter words

I know the string from the first line, so i think the startpattern have to find

Known_string\n
--------------------------------------------------------


the end pattern have to find the next row with
--------------------------------------------------------

But the row with
--------------------------------------------------------
occurs multiple times in the text

Can I match this with awk or sed ?

Best regards, Eric
# 7  
Old 12-06-2007
somewhat ugly, but......
nawk -f eric.awk myFile

eric.awk:
Code:
BEGIN {
  PAT="constant string"
}

$0 ~ PAT {f=1;print;next}
f && /^--*$/ {b=1;print;next}
b,/^--*/
{f=0;b=0}

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