Re: Sed advice needed



On 2007-05-31, Piers Kittel <debian@xxxxxxxxxx> wrote:

"181","1324.014027","111.111.111.111","111.111.111.111","RTP","Payload t
ype=ITU-T H.261, SSRC=2008229573, Seq=54520, Time=1725612773, Mark"
"185","1324.078941","111.111.111.111","111.111.111.111","RTP","Payload t
ype=ITU-T H.261, SSRC=2008229573, Seq=54521, Time=1725616276"

I need to convert the above to the below:

"181","1324.014027","111.111.111.111","111.111.111.111","RTP","54520"
"185","1324.078941","111.111.111.111","111.111.111.111","RTP","54521"

What's the best way to do this? I've been reading the man pages of
sed, cut and awk but I can't quite figure out how to do this. Any
ideas?


If I understand what you want, you need the fields 1-5 and 8 from a
comma-delimited record. At least, that's what cut will see - the
quotes around Payload...Mark will get ignored if you tell cut to use a
, as delimiter:

cut -d, -f1,2,3,4,5,8

Then you just need to get rid of the Seq= line, which sed will do
with:

sed s/Seq=//g

So put them together:

cut -d, -f1,2,3,4,5,8 input.file | sed s/Seq=//g

That looks almost right. I'm missing the quotes around the last field.
Two more sed commands fix this:

cut -d, -f1,2,3,4,5,8 input.file |
sed -e s/Seq=//g -e 's/, /,"/g' -e 's/$/"/g'

That seems to do the job with your example text.

HTH,

Tyler


--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: Sed advice needed
    ... # Remove quotes ... I've been reading the man pages of sed, cut and awk but I can't quite figure out how to do this. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ... Trouble? ...
    (Debian-User)
  • Re: [SLE] Keyboard Layout
    ... Please do us all a big favor and just unsubscribe. ... > I do ACTUALLY start reading almost every book from the back -- the INDEX. ... >>> Dear Ken Schneider, ... Also check the archives at http://lists.suse.com ...
    (SuSE)
  • Re: I got some major problems coming up wrt teaching evolution
    ... >church and state, with a special emphasis on evolution. ... and my heart sank merely by reading the URLs: ... show that the quotes that the ICR quotes are out of context. ...
    (talk.origins)
  • Re: awk and date command
    ... awk -v DT=`date +%Y%m%d` program.awk record.txt ... Country: Australia ... Text or chat with friends inside Yahoo! ... To unsubscribe: ...
    (Fedora)
  • Re: Latham - but really John Brandon
    ... Leo van de Pas ... >> Leo van de Pas, ... > To unsubscribe from the list, ... please send an email to GEN-MEDIEVAL-request@xxxxxxxxxxxx with the word 'unsubscribe' without the quotes in the subject and the body of the message ...
    (soc.genealogy.medieval)