Prev: Changing SAS proc format to if-then-else
Next: Discount Wholesale LV Jeans from china,paypal payment and free shipping
From: lloyd on 21 Jun 2010 13:36 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 21 Jun 2010 13: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. 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 21 Jun 2010 14:25 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 21 Jun 2010 14:30 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 21 Jun 2010 14:35 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
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Changing SAS proc format to if-then-else Next: Discount Wholesale LV Jeans from china,paypal payment and free shipping |