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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get text between two special rows ?( using awk or sed)?
# 1  
Old 08-10-2008
Data 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 lines and store the data between each block in diffrent varaible.

Sushant
# 2  
Old 08-11-2008
What have you done to attempt to solve this problem yourself?
Post your sample script, and we'll see how we can assist.

Regards
# 3  
Old 08-11-2008
i would probably read the file line by line, and inside the while , i would use one or more fis to identify th content of the line.
based on that, take the actions you want with that data.
you could use temporal files, which is easier to work with when you dont know the amount of data blocks, and dont know how many variables you will need to hold that data
# 4  
Old 08-11-2008
Quote:
Originally Posted by Franklin52
What have you done to attempt to solve this problem yourself?
Post your sample script, and we'll see how we can assist.

Regards
I forget to tell that i also know the one line before and after "-------------"
so for that i simply use
sed -ne '/line1/,/line3/p' file name
but i am facing one problem in thats
there is very little diffrence between each before and after statement like this

Runing Test Case LS01
...........
...........
Test Case LS01 Completed
----------------------------

Runing Test Case LS01_A
.................
.........
Test Case LS01_A Completed
----------------------------

Runing Test Case LS02
...............
..............
Test Case LS02 Completed
----------------------------

now if i run the above command like this
sed -ne '/LS01/,/LS01/p' file_name
than its show both block LS01 and LS01_A but i want only LS01

Thanks for helping me
Sushant
# 5  
Old 08-11-2008
try below perl script

Code:
$file=shift;
$del=shift;
print $file,"----",$del,"\n";
open(FH,"<$file") or die "Can not open file";
$n=0;
while(<FH>){
        if((index $_,$del)!=-1){
                print $_;
                $arr[$n]=sprintf("%s%s",$arr[$n],$_);
        }
}
close(FH);
for($i=0;$i<$#arr;$i++){
        print $arr[$i];
        print "******************\n";
}

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

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... (16 Replies)
Discussion started by: eric_
16 Replies

8. 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

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