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 13:37 Tue, 22 Jun 2010 09:43:40 -0400, Jon LaBadie did cat : > 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 not much, that version has the same problem your first post had, as Hermann Peifer nicely put it: "Most of the solutions I've seen posted didn't do what the OP asked for."
From: Jon LaBadie on 22 Jun 2010 20:38 Loki Harfagr wrote: > Tue, 22 Jun 2010 09:43:40 -0400, Jon LaBadie did cat : .... > > not much, that version has the same problem your first post had, > as Hermann Peifer nicely put it: > "Most of the solutions I've seen posted didn't do what the OP asked for." You are correct, my apologies for not understanding what Hermann was pointing out.
From: Rakesh Sharma on 25 Jun 2010 09:14 On Jun 21, 10:36 pm, lloyd <lloyd.hough...(a)gmail.com> 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. sed -e ' :loop / /!d s//\ /2 P s/^\([^ ]*\) // s/\n/ / ba ' yourfile
From: Loki Harfagr on 25 Jun 2010 11:24 Fri, 25 Jun 2010 06:14:37 -0700, Rakesh Sharma did cat : > On Jun 21, 10:36 pm, lloyd <lloyd.hough...(a)gmail.com> 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. > > > sed -e ' > :loop > / /!d > s//\ > /2 > P > s/^\([^ ]*\) // > s/\n/ / > ba > ' yourfile nice but probably better with the loop tag with the same name used for the branch?-) :a or bloop
From: Dominic Fandrey on 27 Jun 2010 06:00 On 22/06/2010 15:40, Ed Morton wrote: > 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? Oh, I'm sorry. It came up with 4.2 BSD and lets you do stuff like defining rows and columns (0: auto #rows, 2: 2 columns) or perform matrix transformations (-T). My guess was that it went into Sys V like most of the early BSD stuff and hence was widely available. # echo word1 word2 word3 word4 word5 word6 ... | rs 0 2 word1 word2 word3 word4 word5 word6 .... Regards -- 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?
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 |