[Techtalk] VI(M) - Changing & Merging 2 lines?

Siobhan Elliott siobhan+lc at spiderland.net
Mon Sep 1 10:03:53 EST 2003


> Hello,
> 
> I have a large text file where 2 lines (fields) form a record.  Now I
> want 
> to merge the 2 lines into one line seperated by a comma.
> 
> Line1
> Line2
> 
> The fields should be seperated by a comma.
> 
> Line1,Line2
> 
> How can I define a keystroke that will,
>     	add a comma at the end of Line1
>     	perform a JOIN of Line1 and Line2
>     	move the cursor to the next record?

sed is your friend:

09:59:04 {363}% cat /tmp/data
cat
house
dog
food
bird
cage

09:59:12 {364}% sed '{
> N
> s/\n/,/
> }' /tmp/data
cat,house
dog,food
bird,cage
09:59:20 {365}%
 
> Any help appreciated.
> 
> Thank you in advance.

Siobhan
-- 
Not only is this incomprehensible, but the ink is ugly and the paper
is from the wrong kind of tree.
                -- Professor W., EECS, George Washington University


More information about the Techtalk mailing list