Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
How to join two text lines on one l
Name: lamos Date: August 18, 2005 at 18:34:01 Pacific OS: Solaris 8 CPU/Ram: 1GB
Comment:
Hi folks,
I am trying to figure out how to join two lines on one line of text. For example, I have a text file with the following text:
TEXT LINE1 0 TEXT LINE2 0 TEXT LINE2 234 TEXT LINE3 236 ... and so on.
I want it to look as follows:
TEXT LINE1 0 TEXT LINE2 0 TEXT LINE3 234 TEXT LINE4 236 ... and so on.
Name: nails Date: August 19, 2005 at 07:38:44 Pacific
Reply:
Hi:
Here's a sed solution:
sed '$!N;s/\n/ /' myfile
but I'd use paste:
paste -s -d" \n" myfile
0
Response Number 2
Name: lamos Date: August 19, 2005 at 10:43:23 Pacific
Reply:
Nails,
The paste option worked nicely. However, I received a garbled message for sed option. I'll use paste instead. Since this worked for one, how can I do multiples? For example:
TEXT LINE1 0 0 TEXT LINE2 0 234 ... on so on.
I'd like to look as follows:
TEXT LINE1 0 0 TEXT LINE2 0 234 .. and so on.
Thanks for you help!
0
Response Number 3
Name: vicchai Date: August 21, 2005 at 17:39:54 Pacific
Reply:
Try this:
#change the num to the lines you want to join num=3 count=$num cat textfile | while read lines do if [ "$count" != "1" ]; then echo $lines | tr '\n' ' ' count=`expr $count - 1` else echo $lines count=$num fi done
0
Response Number 4
Name: lamos Date: August 23, 2005 at 12:55:22 Pacific
Reply:
Hi Vicchai,
Thanks for your suggestion. I used Nails paste command suggestion to perform the task. tmp1.dat contained the above text and numbers.
cat tmp1.dat | paste - - - > tmp2.dat
tmp2.dat contains the numbers on the same line as the text line.
Thanks.
0
Response Number 5
Name: Luke Chi Date: September 8, 2005 at 13:49:07 Pacific
Summary: Hi, How to convert a text file (which is tab delimited) into an .xls file. in unix scripting. I tired renaming the extension of .txt into .xls. It seems to work so but the leading zeros of the cell co...
Summary: Hi , I wish to know how to combine two files to one file using unix command. I had two files aaa and bbb aaa files: 02 02 02 02 02 02 and bbb files : 5646 5646 5646 5646 5646 5646 I need to put it to...