• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SED Question (String tokenize)

 
Serkan Demir
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nl does number lines:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic