Re: Put ID at beginning of data lines

"Eliana" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <TkcMail.1337051159.8918.3@zaurus>
This is not very elegant, but it seems to work.  I added a pipe as a distinct line end indicator so I could put everything together in one long line using tr and then used tr to  go back to one line per individual, and then used sed to swap the ID and data back to proper positions.  I am not sure why the | landed on the ID line by using this particular  code, but what counts is it works:

$ cat x3.sed
/^"/{
h
d
}
G 
/^ /s/$/|/     
$ sed -f x3.sed testx.txt
 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"|                                
$ sed -f x3.sed  testx.txt |tr '\n' ':' | tr '|' '\n'|sed 's/^ *:* *//;s/\(.*\):\(.*\)/\2,\1/'
"1","V3","Johnny Jamison",144058604,149864828
"1","V3","Johnny Jamison",104132262,115218852
"1","V3","Johnny Jamison",40739561,80546082
"2","V2","Janet Anne Doe",145956371,150258170
"2","V2","Janet Anne Doe",125505743,131005138
"2","V2","Janet Anne Doe",53487753,77418759
"2","V2","Janet Anne Doe",32142804,34367848
"3","V2","William Jones",121742874,124782881
"3","V2","William Jones",89861384,107281037 
$

Thanks for helping me figure this out, there might be a more elegant way to do it, but cumbersome  solutions are better than no solutions at all.

The hold space is what was messing me up, I just don't have enough experience using that feature.

Thanks again,
Eliana
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.