Re: Put ID at beginning of data lines
"Eliana" <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <TkcMail.1337049245.8918.2@zaurus> |
> On Mon, May 14, 2012 at 6:57 PM, Jan > FRS <[email protected]> wrote: > > ** > > $ sed -ne '/^"/h;/^[^"]/{G;s/\([0-9,]\+\ > > )\n\(.*\)/\2,\1/p}' data.1 > > > > That'll simplify some: > $ sed -r '/^"/{h;d}; G;s/(.*)\n(.*)/\2,\1/' test.txt Same problem here, unrecognized option, whatever option I use : $ head -n12 testx.txt| sed -e '/^"/{h;d};G;s/(.*)\n(.*)/\2,\1/' sed: -e expression #1, char 9: Extra characters after command $ head -n12 testx.txt| sed -r '/^"/{h;d};G;s/(.*)\n(.*)/\2,\1/' sed: -e expression #1, char 9: Extra characters after command $ I see my sed does recognize the -n option, but has no -r option. But let me try your version in a script, it does work better, although still not quite right on my system: $ cat x3.sed /^"/{ h d } G s/(.*)\n(.*)/\2,\1/ $ sed -f x3.sed testx.sed 144058604,149864828 "1","V3","Johnny Jamison" 104132262,115218852 "1","V3","Johnny Jamison" 40739561,80546082 "1","V3","Johnny Jamison" 145956371,150258170 "2","V2","Janet Anne Doe" 125505743,131005138 "2","V2","Janet Anne Doe" 53487753,77418759 "2","V2","Janet Anne Doe" 32142804,34367848 "2","V2","Janet Anne Doe" 121742874,124782881 "3","V2","William Jones" 89861384,107281037 "3","V2","William Jones" I really think the \n is not recognized by my sed. I will continue to play with this, maybe I can figure something else out, piping output to 'tr' and then back to sed and tr again. Not ideal, but without \n within sed, it does get cumbersome. Eliana