aspose file tools*
The moose likes Linux / UNIX and the fly likes SED Question (String tokenize) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "SED Question (String tokenize)" Watch "SED Question (String tokenize)" New topic
Author

SED Question (String tokenize)

Serkan Demir
Ranch Hand

Joined: Feb 03, 2005
Posts: 61
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


A guy from Turkey<br /><a href="http://blogspot.serkandemir.com" target="_blank" rel="nofollow">http://blogspot.serkandemir.com</a>
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

nl does number lines:


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SED Question (String tokenize)
 
Similar Threads
help with bash
Find & Replace strings/text in JSP's
Replacing a word in a text file
Making multiple files from single file
using sed to chnage data in file