Multiple lines into one using PERL or SHELL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple lines into one using PERL or SHELL
# 1  
Old 06-02-2010
Multiple lines into one using PERL or SHELL

Hi All,

I need your help to solve problem using either PERL script or SHELL script.

We are receving a file, in which one record is coming in multiple rows. The main problem is, we are not able to differenciate when the 1st record ends and where the second record starts.

For example,
Code:
 
I
am 
a
student
in 
which 
company
are
you working

Actually, these should be as follow
Code:
 
I am a student
In which company are you working.

Can someone help me to solve this problem. I was asked to use CHOMP of perl to solve this problem but when i googled, i found that CHOMP is use to remove any newline character from the end of the string.

I really do not understand, how to get rid of it.
# 2  
Old 06-02-2010
From the sample you have provided, it would be difficult to solve your problem using a simple shell script.

What signifies the end of a sentence? A period perhaps.

Peace
# 3  
Old 06-02-2010
Quote:
Originally Posted by Amit.Sagpariya
The main problem is, we are not able to differenciate when the 1st record ends and where the second record starts.
That's a BIG problem.
# 4  
Old 06-02-2010
Quote:
Originally Posted by Amit.Sagpariya
...The main problem is, we are not able to differenciate when the 1st record ends and where the second record starts.
...
I really do not understand, how to get rid of it.
I think the best thing to do is to talk to the person/department/group/team that generates your data file and ask them to put a delimiter character that marks the end of a record. Or maybe enclose the multiline records within double quotes.

Put simply, if a human being cannot figure out the end of a record, then most definitely, a computer can not figure that out too !

tyler_durden
# 5  
Old 06-03-2010
Hi All,

I have found some idea to handle this situation.

Actually, each lines contains only 80 characters. But as per specification document, 540 characters are of HEADER and then 540 characters are of DETAIL RECORD and very last row is FOOTER record.

In this case, 6 lines (of 80 characters) and 7th lines (with 60 characters) is a HEADER RECORD.

Starting from 61th caracter of 7th lines till 40th character of 14th lines will be DETAIL RECORD 1 and so on...

Is it possible to read line by line and count the characters and seperate the record?

Can somebody help me to write this type of logic or any other idea?

Last edited by Amit.Sagpariya; 06-04-2010 at 03:22 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and swap multiple lines in file using Perl

Hi all, I have a vcd file with a bunch of lines containing an array, like this $var wire 1 b a $end $var wire 1 c a $end $var wire 1 d a $end $var wire 1 e a $end $var wire 1 f b $end $var wire 1 g b $end $var wire 1 h b $end $var wire 1 i b $end I want it like this: $var wire 1 e a... (12 Replies)
Discussion started by: veerabahu
12 Replies

2. Programming

PERL:Combining multiple lines to single line

Hi All I need a small help for the below format in making a small script in Perl or Shell. I have a file in which a single line entries are broken into three line entries. Eg: I have a pen and notebook. All i want is to capture in a single line in a separate file. eg: I have a pen and... (4 Replies)
Discussion started by: Kalaiela
4 Replies

3. Shell Programming and Scripting

Perl Regex matching multiple lines

I need a way to extract data from X 4T Solution 21 OCT 2011 37 .00 to account 12345678 User1 user2 X 4T Solution Solution Unlimited 11 Sep 2009 248 .00 to account 87654321 user3 user4 I need it to extract 'X' '37.00' and account number 12345678. I have extracted above stuff... (3 Replies)
Discussion started by: chakrapani
3 Replies

4. Shell Programming and Scripting

Perl: substitute multiple lines

I'd like to do this using Perl command line (sorry no awk, sed, etc.) replace the 3 middle lines in a file by one line: aaa 123 bbb 234 ccc 34567 dd 4567 ee 567 to: aaa 123 AAA ee 567 I tried this but not working: perl -pi -e "s/aaa\ 123\nbbb\ 234\nccc\ 34567/AAA/" file (2 Replies)
Discussion started by: tintin78899
2 Replies

5. Shell Programming and Scripting

Using Perl to Merge Multiple Lines in a File

I've hunted and hunted but nothing seems to apply to what I need. Any help will be much appreciated! My input file looks like (Unix): marker,allele1,allele2 RS1002244,1,1 RS1002244,1,3 RS1002244,3,3 RS1003719,2,2 RS1003719,2,4 RS1003719,4,4 Most markers are listed 3 times but a few... (2 Replies)
Discussion started by: Peggy White
2 Replies

6. Shell Programming and Scripting

Perl: Printing Multiple Lines after pattern match

Hello People, Need some assistance/guidance. OUTLINE: Two files (File1 and File2) File1 has some ids such as 009463_3922_1827 897654_8764_5432 File2 has things along the lines of: Query= 009463_3922_1827 length=252 (252 letters) More stufff here ... (5 Replies)
Discussion started by: Deep9000
5 Replies

7. Shell Programming and Scripting

[Help] PERL Script - grep multiple lines

Hi Gurus, I need some help with the "grep" command or whatever command that you think suitable for me. I'm about to write a perl script to extract a report from the system and submit it to the end users. The input for the script will consist of 3 element. 1) Generation ID 2) Month 3) Year... (6 Replies)
Discussion started by: miskin
6 Replies

8. Shell Programming and Scripting

PERL: add string to multiple lines

Dear all, I am stuck while trying to add a string to multiple lines. Let me try to explain using an example: Input: -------- myExample_send ("MasterSends", n, "Data Type", MPI_INT); correct Output:... (4 Replies)
Discussion started by: bonny
4 Replies

9. Shell Programming and Scripting

read and match multiple lines in perl

Could any one tell me how to read and match multiple lines in perl? Did this code below still work in this situation? while (<FILE>) { if (/ /) { } } Thanks a lot! (5 Replies)
Discussion started by: zx1106
5 Replies

10. Shell Programming and Scripting

Adding 3 Lines to Multiple c and h files with perl

Hello, i need some help with a perl script. i need to add the lines: #ifdef LOGALLOC #include "logalloc.h" #endif // LOGALLOC To all c and h files in a project with subdirectories. Logalloc is a tool to log all *alloc and free's in a text file, it defines the *alloc funtions new.... (2 Replies)
Discussion started by: Lazzar
2 Replies
Login or Register to Ask a Question