Computing.Net > Forums > Unix > Join 2 lines into 1

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Join 2 lines into 1

Reply to Message Icon

Name: pirracas77
Date: January 25, 2007 at 00:47:48 Pacific
OS: Solaris 9
CPU/Ram: .
Product: .
Comment:

Hello!!!
I've just in a old post how to join 2 lines into 1. I need to do similar but I don't know the amount of lines that I must join beforehand.

For example:

TEXT1
123
41
51
TEXT2
12
TEXT3
12
13
14

...and I want that the output like this:

TEXT1 123 41 51
TEXT2 12
TEXT3 12 13 14
..and so on.
Any suggestions?

Thanks a lot!!!



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: January 25, 2007 at 08:06:12 Pacific
Reply:

A way ....

#!/bin/ksh

# shell match function
matchre() { expr "$1" : "$2" >/dev/null 2>&1; }

count=0
while read line
do
((count+=1))
if matchre "$line" "TEXT"
then
if [[ $count -gt 1 ]]
then
printf "\n%s " "$line"
continue
fi
fi
printf "%s " "$line"
done < text.file


0

Response Number 2
Name: kokni
Date: March 2, 2007 at 15:04:56 Pacific
Reply:

How could the following line

if matchre "$line" "TEXT"

be transformed to match any given combination of 6 digits (my database ids) instead of the string TEXT?


0
Reply to Message Icon

Related Posts

See More


Error: cygwin1.dll determine cal



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Join 2 lines into 1

sed - reverse every 2 lines www.computing.net/answers/unix/sed-reverse-every-2-lines/5788.html

Vi search across carriage return www.computing.net/answers/unix/vi-search-across-carriage-return/6306.html

Merging 2 lines www.computing.net/answers/unix/merging-2-lines/5084.html