• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SED Question (String tokenize)

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I have a question with SED and its text processing capability.
I have a file with entries similar to below which are separated with ';'.
0;20070718095600;514;3;-1508598133;3;0;905332000000;905331374678;163;0;0;0;0;-002094771550:31fc6b2:113d8159c7f:-7ec1;0;0;5;0;20070718095559;1111905332000000;;2;994508887766;0;;;0;;20;1;-002094771550:31fc6b2:113d8159c7f:-7ec1;0;0;2001;1;98765

I want to separate this line into tokens by delimiting ';' and put index numbers before it.
eg:
1) 0
2) 20070718095600
3) 514
4) 3
5)
.
.
.
37)

I have been playing with sed, but i am unsuccessful to do this. Could you help me with this?

Thanks lot,

Serkan
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't use sed to do a single character replace; I would use "tr", just like

tr \; \\n

The whole thing could look something like this:

n=1
for i in `tr \; \\\n < THEFILE`; do echo $n\) $i; n=`expr $n + 1` ; done

Probably someone else could do this more elegantly.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nl does number lines:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic