Results 1 to 8 of 8
Hi,
I'm quite new to Linux and Linux scripting and I would like to know how to deal with the following task:
I have a text file which consist one ...
- 06-13-2008 #1Just Joined!
- Join Date
- Jun 2008
- Posts
- 3
One long line to many separate lines
Hi,
I'm quite new to Linux and Linux scripting and I would like to know how to deal with the following task:
I have a text file which consist one long row. Row is basically in xml syntax and may have lot of fields. Source example:
<data1>1a</data1><data2>2b</data2><data3>3c</data3>…<dataN>Nn</dataN>
Now I should populate the file so that every field in that long line goes into separate row. Result example:
<data1>1a</data1>
<data2>2b</data2>
<data3>3c</data3>
…
<dataN>Nn</dataN>
What might be the best way to receive the result above?
Thanks,
--
Don
- 06-13-2008 #2
hi,
with this you should be OK
Code:sed -i 's/></>\n</g' file_name
Linux and me it's a love story
- 06-13-2008 #3Just Joined!
- Join Date
- Jun 2008
- Posts
- 3
Hi,
Thanks khafa! Today I work with Windows and I downloaded sed -software for Win. I run sed to make simple changes to example file and there were ok. For example code below worked perfectly:
sed -i "s/1a/AAA/g" file_name.txt
The "1a" was replaced with "AAA".
Then I had some problems with the code your kindly sent (little modified):
sed -i "s/></AAA/g" file_name.txt
When I run the code from above in command prompt it didn't replace "><" with "AAA". I tried some of this and some of that, but without success. Should "><" -chars in the pattern be used with some special characters?
Thanks again!
--
Don
- 06-13-2008 #4
- 06-13-2008 #5Just Joined!
- Join Date
- Jun 2008
- Posts
- 3
Hi,
Sorry, my mistake. Khafa's code works like it should.
--
Don
- 06-13-2008 #6
dont worry. welcome to the wonderful Linux world
Linux and me it's a love story
- 06-14-2008 #7Linux User
- Join Date
- Aug 2006
- Posts
- 458
it might be better to consider situations like this: (spaces in between)
eg
<data1>1a</data1> <data2>2b</data2> <data3>3c</data3>…<dataN>Nn</dataN>
Code:sed 's/> *</>\n</g' file
- 06-14-2008 #8Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044


Reply With Quote
