From: lloyd on
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.
From: pk 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.

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)}'
From: Radoulov, Dimitre 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


printf '%s %s\n' $(<infile)

or

tr \ \\n < infile | paste - -



Regards
Dimitre

From: Hermann Peifer on
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)}'

Hermann
From: Radoulov, Dimitre on
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
>
>
> printf '%s %s\n' $(<infile)
>
> or
>
> tr \ \\n < infile | paste - -

Ignore please (just saw Hermann Peifer's reply and re-read the original
post).



Dimitre