Critical problem in merging lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Critical problem in merging lines
# 1  
Old 02-12-2009
Critical problem in merging lines

Hi all, I am having a very critical problem in merging lines in my file as, let my file contents are:
cat test1.txt
name1.......
address1.......
phone1......
<blank>
name2......
address2.....
phone2.....
<blank>
and so on. Now i have to merge these lines by which my desired output becomes:
name1...... address1..... phone1......
name2..... address2..... phone2.....
I use the commands found in a forum:
cat test1.txt | tr -d '\n' > test2.txt (also tried: sed -e :a -e N -e 's/\n/ /' -e ta test.txt > test2.txt)
and got the result like:
name1........ address1........
phone1.......
<blank>
name2....... address2........
phone2.........
<blank>

When i tried to put single quote(') at the begning and end of each line using command
sed "s/^/'/g; s/$/'/g" test2.txt > test3.txt
it gives output as
'name1...... address1......
phone1......
<blank>
name2...........address2...............
phone2..................
<blank>
'
Problem 1: it consider whole file as single line and put single quotes at the starting of file and at end of file. So how could i sort this problem?
Problem2: How could i get the desired output ?

Please help me guys, this is very urget for me Smilie
Thanks in advance
# 2  
Old 02-12-2009
Quote:
Originally Posted by shadow25
Problem2: How could i get the desired output ?
If you need help post a data sample enclosed in [code] tags Smilie
# 3  
Old 02-13-2009
Hi, my sample code is
[ -A.N.Sood
25, SHEKHAR PRIDE 11/20 SOUTH TUKOGANJ NEAR KADAMBARI SAREE INDORE
Phone : 4303826 Mobile : 9344257687

-ISMAIL SIDHHQUE
L-30,TRADE CENTER 51,SOUTH TUKOGANJ INDORE
Phone : 4867461 9412570055 Mobile : 9855670001
]

I want this file to be converted into:
'A.N.Sood ',' 25, SHEKHAR PRIDE 11/20 SOUTH TUKOGANJ NEAR KADAMBARI SAREE INDORE ',' Phone : 4303826 Mobile : 9344257687'
'ISMAIL SIDHHQUE ',' L-30,TRADE CENTER 51,SOUTH TUKOGANJ INDORE ',' Phone : 4867461 9412570055 Mobile : 9855670001'

How could i convert file into the required file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

2. Shell Programming and Scripting

Merging 2 lines together

I have a small problem, which due to my lack of knowledge, has left me unable to decipher some of the solutions that I looked at on these forums. So below is a piece of text, which I ran via cat -vet, which comes from within a program file. I have many such programs to process and repeatable,... (4 Replies)
Discussion started by: skarnm
4 Replies

3. Shell Programming and Scripting

Merging lines

Thanks it worked for me. I have one more question on top of that. We had few records which were splitted in 2 lines instead of one. Now i identified those lines. The file is too big to open via vi and edit it. How can i do it without opening the file. Suppose, I want line number 1001 & 1002 to... (2 Replies)
Discussion started by: Gangadhar Reddy
2 Replies

4. Programming

Single semare critical region problem???

Hi guys, I hope everybody is doing fine. I have written this small program which solves the critical region problem. Only on of the two threads can make changes to a common variable called counter. I am using two semaphores, is it possible to write the same program using only one semaphore? Here... (0 Replies)
Discussion started by: gabam
0 Replies

5. Shell Programming and Scripting

merging two .txt files by alternating x lines from file 1 and y lines from file2

Hi everyone, I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines). Does anybody have an idea how to do that using perl, awk or sed?... (6 Replies)
Discussion started by: ink_LE
6 Replies

6. Shell Programming and Scripting

Merging lines

Hi folks. Could somebody help me write a script or command that will look through a file and for every line that doesn't contain a certain value, merge it with the one above? For example, the file contains: SCOTLAND|123|ABC|yes SCOTLAND|456|DEF|yes SCOTLAND|78 9|GHI|yes ... (3 Replies)
Discussion started by: MDM
3 Replies

7. Shell Programming and Scripting

merging similar lines

Greetings, I have been trying to merge the following lines: Sat. May 9 8:00 PM Sat. May 9 8:00 PM CW Sat. May 9 8:00 PM CW Cursed Sat. May 9 9:00 PM Sat. May 9 9:00 PM CW Sat. May 9 9:00 PM CW Sanctuary Sat. May 16 8:00 PM Sat. May 16 8:00 PM CW Sat. May 16 8:00 PM CW Sanctuary Sat. May... (2 Replies)
Discussion started by: adambot
2 Replies

8. Shell Programming and Scripting

Conditional merging of lines

I have a large file where some lines have been split into two lines; some of them even with white spaces before the second line. e.g in the following text I want to merge only specific lines ( say UNIX is cool), also removing white spaces only between them, others shall remain same on the output.... (4 Replies)
Discussion started by: sunny23
4 Replies

9. UNIX for Dummies Questions & Answers

merging two lines in a file

Hi All, I want to merge two lines in a file till the end of the file. So what could be the command to get so. say file name : sample.txt contents: country=1 send apps =1 rece=2 country=2 send apps =3 rece=3 .. ... output: country=1;send apps =1 rece=2 country=2;send apps =3... (6 Replies)
Discussion started by: thaduka
6 Replies

10. UNIX for Dummies Questions & Answers

Merging lines into one

Hello. I would be very pleased if sb. help me to solve my problem. I've got a file with many non blank lines and I want to merge all lines into one not destroy the informations on them. I've tryed it with split and paste, tr, sed , but everything I've done has been wrong. I know about crazy... (8 Replies)
Discussion started by: Foxgard
8 Replies
Login or Register to Ask a Question