sed help split line


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users sed help split line
# 1  
Old 01-30-2006
sed help split line

hi

i have a file containing lines like

word1,word2,word3,word4,..
word4,word5,word3,word6,...

now i need to make it to look like
word1
word2
word3
word4
.
.
.

in other words ','(comma) is replaced with new line.
# 2  
Old 01-30-2006
Much easier with tr.

Code:
tr ',' '\n' < input.file

# 3  
Old 01-30-2006
If you want to use sed (tested with GNU sed, plus sed on a Solaris 9 box)...
Code:
sed 's/,/\
/g' my_file

Hit return after the backslash....

Cheers
ZB
# 4  
Old 01-30-2006
thanks vino that works

sorry zazzy sed failed!!
# 5  
Old 01-30-2006
Quote:
Originally Posted by Raom
thanks vino that works

sorry zazzy sed failed!!
The sed should work perfect.

Try this as well...

Code:
sed -e 's_,_\n_g' input.file

# 6  
Old 01-30-2006
Yep the sed should work fine. It will fail if you're using csh/tcsh it'll barf.

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed split string

Greetings, i have a string that looks like Network "123" "ABC" i need to make it look like: Network "123" Network "ABC" Help please? Thanks again Please use CODE tags when displaying sample input, sample output, and code segments (as required by forum rules). (2 Replies)
Discussion started by: hoyanet
2 Replies

2. Shell Programming and Scripting

Split a line

I have a very long line in a file separated by "|" delimiter like below. Due to the length of the line, I find it very difficult to read to find a match line. file = temp.txt word 1| word 2 | word 3|.... I would like to read the file temp.txt and print out all words line by line like... (1 Reply)
Discussion started by: boldnbeautiful
1 Replies

3. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

4. Shell Programming and Scripting

Split a line

I guess this has a simple solution but can't figure out now. having: x="H:a:b:c" to get H: echo $x|awk -F: {'print $1'} how can I put REST of line in another one? i.e. echo $rest a:b:c thanks ---------- Post updated at 08:58 PM ---------- Previous update was at... (5 Replies)
Discussion started by: garagonp
5 Replies

5. Shell Programming and Scripting

Split line to multiple files Awk/Sed/Shell Script help

Hi, I need help to split lines from a file into multiple files. my input look like this: 13 23 45 45 6 7 33 44 55 66 7 13 34 5 6 7 87 45 7 8 8 9 13 44 55 66 77 8 44 66 88 99 6 I want to split every 3 lines from this file to be written to individual files. (3 Replies)
Discussion started by: saint2006
3 Replies

6. Shell Programming and Scripting

split single line into two line or three lines

Dear All, I want to split single line into two line or three lines wherever “|” separated values comes using Input line test,DEMTEMPUT20100404010012,,,,,,,,|0070086|0070087, output shoule be test,DEMTEMPUT20100404010012,,,,,,,,0070086, test,DEMTEMPUT20100404010012,,,,,,,,0070087, (14 Replies)
Discussion started by: arvindng
14 Replies

7. Shell Programming and Scripting

Split a line based on : using sed

Hi, i have a file say file1 having following data /abc/def:ghi/jkl/ some other text Now i want to extract only ghi/jkl/using sed, can some one please help me. Thanks Sarbjit (2 Replies)
Discussion started by: sarbjit
2 Replies

8. Shell Programming and Scripting

awk or sed to split dn

Hello - I have an input file with user dn's. e.g. cn=peter,cn=users,dc=com,dc=uk cn=simon,cn=users,dc=com,dc=uk cn=john,cn=users,dc=com,dc=uk cn=fred,cn=users,dc=com,dc=uk My script needs to generate an LDIF file based on this input file as below:- awk '{ FS=""} { print... (1 Reply)
Discussion started by: sniper57
1 Replies

9. Shell Programming and Scripting

Split a line on positions before reading complete line

Hi, I want to split before reading the complete line as the line is very big and its throwing out of memory. can you suggest. when i say #cat $inputFile | while read eachLine and use the eachLine to split its throwing out of memory as the line size is more than 10000000 characters. Can you... (1 Reply)
Discussion started by: vijaykrc
1 Replies

10. Shell Programming and Scripting

Split a huge line into multiple 120 characters lines with sed?

Hello , I'm trying to split a file which contains a single very long line. My aim is to split this single line each 120 characters. I tried with the sed command : `cat ${MYPATH}/${FILE}|sed -e :a -e 's/^.\{1,120\}$/&\n/;ta' >{MYPATH}/${DEST}` but when I wc -l the destination file it is... (2 Replies)
Discussion started by: jerome_1664
2 Replies
Login or Register to Ask a Question