If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > splitting a string

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-03-06, 10:12
davidcollins001 davidcollins001 is offline
Registered User
 
Join Date: Feb 2006
Posts: 15
splitting a string

hi,

I have a number of filenames made up of letters and numbers like the following:

01-000.134off.log
01-000.14off.log
01-000.4off.log

What I would like to do is to strip away everything leaving just the non zero numbers ie:

134
14
4

I have managed to get this using grep and sed with no problem. What I really want to do next is split the string of numbers into single digits so that I am left being able to use the digits to place in another part of the program.

Is this possible, I haven't been able to find the answer and I can't think of how to do it?
thanks
Reply With Quote
  #2 (permalink)  
Old 03-03-06, 13:23
hyperbole hyperbole is offline
Registered User
 
Join Date: Jan 2006
Posts: 32
Quote:
What I really want to do next is split the string of numbers into single digits
I'm not sure what you mean by this.

If you want the digits separated on a single line add
Code:
-e 's/\(.\)/\1 /g'
to your sed statement

If you want each digit on a separate line use
Code:
-e 's/\(.\)/\1^M/g'
where you create ^M by pressing Ctrl-V, Enter.



.
Reply With Quote
  #3 (permalink)  
Old 03-06-06, 03:54
davidcollins001 davidcollins001 is offline
Registered User
 
Join Date: Feb 2006
Posts: 15
Thank you, I had spent ages trying to work this out. The top one works just as I wanted it to!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On