Multiline read with multicharacter record seperator


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiline read with multicharacter record seperator
# 1  
Old 02-12-2009
Multiline read with multicharacter record seperator

I have a file like the below:

Start
<</NumCopies 0001>>
0223 098 et(5926)sh
0223 098 mt(5926)sh
End
Start
<</NumCopies 0001>>
0224 098 et(5926)sh
0224 098 mt(5926)sh
End


This file needs to be split to seperate files. Each of the seperate file will need to contain whatever is inside the start and end. Including the patterns start and end

I tried using awk with RS="End". But it doesnt work well on more than one charater. Any thoughts how this can be done.
# 2  
Old 02-12-2009
will create output files 'file<number>':
Code:
nawk 'BEGIN{ f="file";cnt=1} /Start/ {close(out);out=f cnt++}; /Start/,/End/ {print >out}' myInputFile

# 3  
Old 02-12-2009
Thanks. Works perfectly well for me.
Was also trying out csplit.

csplit filename /End/ {2}

But it doesnt include the End pattern itself in the split files.
# 4  
Old 02-12-2009
Code:
#!/usr/bin/perl
open FH,"a.txt";
while(<FH>){
	if (/Start/){
		$n++;
	}
	$arr[$n].=$_;	
}
close FH;
for(my $i=0;$i<$#arr;$i++){
	$file=sprintf("out%d.txt",$i);
	open FH,">$file";
	print FH $arr[$i+1];
	close FH;
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command in multicharacter

Hello, I have some problem about sed command. I have data which showed in below : M001 ndle1 M002|bfn|n|bfn|bf ndle1 M003|bfn|n|bf|bf ndle1 M004|bfn|n|bf middle1 M005|bfn|n|bfn|bf middle1 M006|bnf|n|bfn|bf middle1 M007|fn|q|n|bf middle1 The expected... (3 Replies)
Discussion started by: awil
3 Replies

2. Shell Programming and Scripting

Read a multiline text from a console - supporting arrow keys

Hi, I try to read a multiline text from a console and write it to a file using a bash script. I want to end reading from a console if a user types the key twice. I tried this loop: while read LINE; do if 2>/dev/null; then break fi echo -e ${LINE} >> $file done However, it doesn't... (8 Replies)
Discussion started by: wenclu
8 Replies

3. Shell Programming and Scripting

Print first and last line from multiline record

Hi - I'm new to working with multiline records and I'm going nuts trying to do something that seems simple. Input: Tue May 1 14:00 Header Record 1 is valid. Tue May 1 14:00 processing data to 25-Mar-2012 09:00:23.15 Tue May 1 14:03 Header Record 1 is valid. Tue May 1 14:03 processing data... (4 Replies)
Discussion started by: Catullus
4 Replies

4. Shell Programming and Scripting

Unable to read the first space of a record in while loop

I have a loop like while read i do echo "$i" . . . done < tms.txt The tms.txt contians data like 2008-02-03 00:00:00 <space>00:00:00 . . . 2010-02-03 10:54:32 (2 Replies)
Discussion started by: machomaddy
2 Replies

5. Shell Programming and Scripting

Regarding multiline record searching with specific pattern

Dear Experts, I need to extract specific records from one file which has multiline records. Input file pattern is: ============ aaaaaaaa bbbbbbbb asdf 1234 cccccccc dddddddd ============ aaaaaaaa bbbbbbbb qwer 2345 cccccccc dddddddd (7 Replies)
Discussion started by: dhiraj4mann
7 Replies

6. Shell Programming and Scripting

Awk Multiline Record Combine?

I'm trying to use Awk to get the id and name fields ($1 and $2) of file1 combined with their corresponding multiline records in file2 that are separated by blank line. Both files are ordered so that the first line of file1 corresponds to the first set of multiline records in file2 and so on. ... (4 Replies)
Discussion started by: RacerX
4 Replies

7. Shell Programming and Scripting

Read the record from a text file

Hi I want to read one row record from a text file. For eg: I have Sample.txt file with one row of record like 123456768 I want to get the above value from the file and assign it to a variable in my script. Please guide me how to proceed. Thanks, Soll (2 Replies)
Discussion started by: sollins
2 Replies

8. UNIX for Dummies Questions & Answers

how to read record by record from a file in unix

Hi guys, i have a big file with the following format.This includes header(H),detail(D) and trailer(T) information in the file.My problem is i have to search for the character "6h" at 14 th and 15 th position in all the records .if it is there i have to write all those records into a... (1 Reply)
Discussion started by: raoscb
1 Replies

9. Shell Programming and Scripting

transforming a multiline record to single line

Hi All I have a file like this <LText>gvsvdkag<LREC>bdjvdj</LREC>nididyvv</LText> <LText>gvsvdkag<LREC>bdj vdj</LREC>nididyvv</LText> <LText>gvsvdkag<LREC>b djvdj</LREC>nididyvv</LText> <LText>gvsvdkag<LREC>bdjvdj</LREC>nididyvv</LText> How will i change the file to ... (9 Replies)
Discussion started by: anju
9 Replies

10. Shell Programming and Scripting

read record from file

Hi all I have file f1 like this: Set AM/PM indicator to PM started|14155| Generate Error Re|7| Projected Cash Ba|741| Roll System Date |4| Projected Cash Balances started|2| Process Mark To Market started|13429| Process paydowns started|14189| Process Fixed Inc|439| Process Mark To... (3 Replies)
Discussion started by: koti_rama
3 Replies
Login or Register to Ask a Question