The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Splitting the line in multiple lines dd_sh Shell Programming and Scripting 3 03-31-2008 01:54 PM
Splitting a line spindoctor UNIX for Dummies Questions & Answers 16 07-10-2007 02:29 PM
Splitting a single line into multiple lines thanuman Shell Programming and Scripting 4 02-23-2005 04:56 AM
splitting the files sounder123 Shell Programming and Scripting 1 06-04-2004 07:03 AM
Splitting a line up lilas UNIX for Dummies Questions & Answers 1 03-12-2001 12:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-29-2005
evoGage evoGage is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 4
Line Splitting

Hi, I want to make a new line between for eg: 0102030405 to make it look like:

01
02
03
04
05

by using sed commands. I'm just wondering how would I do this?

p.s i'm new to this unix programming.
  #2 (permalink)  
Old 11-29-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Which OS??

If you've got the fold command....

Code:
$ echo "0102030405" | fold -w 2
01
02
03
04
05
Cheers
ZB
  #3 (permalink)  
Old 11-30-2005
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
using sed

Code:
echo "0102030405" | sed 's/\(..\)/\1\
/g'
  #4 (permalink)  
Old 11-30-2005
evoGage evoGage is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 4
Quote:
Originally Posted by mona
using sed

Code:
echo "0102030405" | sed 's/\(..\)/\1\
/g'
Tried it but it says "sed: -e expression #1 char 14: Unterminated `s' command"

What does this mean?
  #5 (permalink)  
Old 11-30-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
You should enter that sed command as given, over two lines. In the given sed command, there is a new line character which is introduced. When you put the whole thing in 1 line, the new line character disappears and then it would throw the error.

Try the same command as

Code:
echo "0102030405" | sed 's/\(..\)/\1\n/g'
  #6 (permalink)  
Old 11-30-2005
evoGage evoGage is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 4
Hi, that works. How would I do it if its like for eg: 44440102030405 to:

4444
01
02
03
04
05
  #7 (permalink)  
Old 11-30-2005
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
not sure of how to do in sed

but here's one more way

Code:
# !/usr/bin/bash
a=0102030405
pos=0
while [ $pos -lt ${#a} ]
do
echo ${a:$pos:2}
pos=$(($pos + 2))
done
exit 0
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0