From: pk on
Hermann Peifer wrote:

> On 21/06/2010 19:36, pk wrote:
>> lloyd wrote:
>>
>>> A textfile looks like this:
>>>
>>> word1 word2 word3 word4 word5 word6 ...
>>>
>>> I want to make it look like this:
>>>
>>> word1 word2
>>> word2 word3
>>> word3 word4
>>> word4 word5
>>> ...
>>>
>>> so that every adjacent pair of words appears as one line of the new
>>> file.
>>> Can someone give me a quick clue how to accomplish this? Many thanks.
>>
>> awk -v RS=' ' 'ORS=NR%2?FS:"\n"'
>>
>> which however adds a trailing newline, or also
>>
>> awk '{for(i=1;i<NF;i+=2) print $i,$(i+1)}'
>
> awk '{for(i=1;i<NF;i++) print $i,$(i+1)}'

Doh, right. I read too quickly. Thank you.
From: Radoulov, Dimitre on
On 21/06/2010 20.35, Radoulov, Dimitre wrote:
> On 21/06/2010 20.25, Radoulov, Dimitre wrote:
>> On 21/06/2010 19.36, lloyd wrote:
>>> A textfile looks like this:
>>>
>>> word1 word2 word3 word4 word5 word6 ...
>>>
>>> I want to make it look like this:
>>>
>>> word1 word2
>>> word2 word3
>>> word3 word4
>>> word4 word5

[...]

With Perl

perl -lane'
print shift @F, " $F[0]" while @F > 1
' infile


Dimitre

From: Jon LaBadie on
lloyd wrote:
> A textfile looks like this:
>
> word1 word2 word3 word4 word5 word6 ...
>
> I want to make it look like this:
>
> word1 word2
> word2 word3
> word3 word4
> word4 word5
> ...
>
> so that every adjacent pair of words appears as one line of the new
> file.
> Can someone give me a quick clue how to accomplish this? Many thanks.

Most of the solutions I've seen posted had difficulty with lines
containing an odd number of words. As the OP did not indicate
how to handle this situation, here is a solution that continues
word pairing across record (line) boundaries.

awk '{for (i=1; i<= NF; i++) printf "%s%c", $i, (++w%2) ? " " : "\n" }'
From: Hermann Peifer on
On 21/06/2010 21:03, Jon LaBadie wrote:
> lloyd wrote:
>> A textfile looks like this:
>>
>> word1 word2 word3 word4 word5 word6 ...
>>
>> I want to make it look like this:
>>
>> word1 word2
>> word2 word3
>> word3 word4
>> word4 word5
>> ...
>>
>> so that every adjacent pair of words appears as one line of the new
>> file.
>> Can someone give me a quick clue how to accomplish this? Many thanks.
>
> Most of the solutions I've seen posted had difficulty with lines
> containing an odd number of words. As the OP did not indicate
> how to handle this situation, here is a solution that continues
> word pairing across record (line) boundaries.
>
> awk '{for (i=1; i<= NF; i++) printf "%s%c", $i, (++w%2) ? " " : "\n" }'

Most of the solutions I've seen posted didn't do what the OP asked for.

Hermann
From: Dominic Fandrey on
On 21/06/2010 19:36, lloyd wrote:
> A textfile looks like this:
>
> word1 word2 word3 word4 word5 word6 ...
>
> I want to make it look like this:
>
> word1 word2
> word2 word3
> word3 word4
> word4 word5
> ...
>
> so that every adjacent pair of words appears as one line of the new
> file.
> Can someone give me a quick clue how to accomplish this? Many thanks.

rs 0 2 < OLDFILE > NEWFILE

works for me.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?