Prev: Changing SAS proc format to if-then-else
Next: Discount Wholesale LV Jeans from china,paypal payment and free shipping
From: Loki Harfagr on 22 Jun 2010 05:02 Mon, 21 Jun 2010 21:17:56 +0200, Hermann Peifer did cat : > 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 now let's try something clunky ;-) $ unset a && <yourfile tr ' ' '\n' |while read b; do [ $a ] && printf "$a $b \n"; a=$b; done
From: Ed Morton on 22 Jun 2010 09:40 On 6/22/2010 3:51 AM, Dominic Fandrey 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 >> ... >> >> 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. > I've never heard of "rs" and I don't have it on any machine I use. What does it do and what does it's output look like given the above input? Ed.
From: Jon LaBadie on 22 Jun 2010 09:43 Loki Harfagr wrote: > Mon, 21 Jun 2010 21:17:56 +0200, Hermann Peifer did cat : > >> 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 > > now let's try something clunky ;-) > $ unset a && <yourfile tr ' ' '\n' |while read b; do [ $a ] && printf "$a $b \n"; a=$b; done Most of the words are duplicated, printed as both $b and $a. I think this version works. unset a && <yourfile tr ' ' '\n' |while read b; do [ $a ] && {printf "$a $b \n"; b=''; }; a=$b; done
From: lloyd on 22 Jun 2010 10:54 Hermann Peifer wrote: > awk '{for(i=1;i<NF;i++) print $i,$(i+1)}' Thanks Hermann, this works just fine. Thanks everyone else, too. It's amazing how many different ways there are to do something like this.
From: Janis Papanagnou on 22 Jun 2010 10:54 Ed Morton schrieb: > On 6/22/2010 3:51 AM, Dominic Fandrey 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 >>> ... >>> >>> 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. >> > > I've never heard of "rs" and I don't have it on any machine I use. What > does it do and what does it's output look like given the above input? I've had the same problem. It seems to be a FreeBSD specific thing. http://www.unix.com/man-page/freebsd/1/rs/ Janis > > Ed.
First
|
Prev
|
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 |