Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-11-2004, 10:38 AM
|
#1
|
|
Member
Registered: Oct 2004
Location: Texas
Distribution: Ubuntu - Home, RHEL4 - Server
Posts: 96
Rep:
|
exploding string into individual characters using a shell script
I am having trouble exploding a URL into a list of individual characters into a file using a linux bash script.
Example:
p.t.com >> Into:
p
.
t
.
c
o
m
I fiddled around with it yesterday and I guess i am having a brain malfuction. Can someone help me out? I'd be forever in your service.
Thanks,
famerjoe
|
|
|
|
10-11-2004, 10:42 AM
|
#2
|
|
Senior Member
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897
Rep:
|
If there's no space in your URL, then maybe this:
Code:
echo "$URL" | sed 's|\([^[:space:]]\)|\1 |g' | sed 's| |\n|g'
Yves.
|
|
|
|
10-11-2004, 10:53 AM
|
#3
|
|
Member
Registered: Oct 2004
Location: Texas
Distribution: Ubuntu - Home, RHEL4 - Server
Posts: 96
Original Poster
Rep:
|
thanks so much. Worked like a dream!
-farmerjoe
|
|
|
|
10-11-2004, 03:46 PM
|
#4
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
Quote:
|
echo "$URL" | sed 's|\([^[:space:]]\)|\1 |g' | sed 's| |\n|g'
|
Or simpler:
Code:
echo "$URL" | sed 's/./&\n/g'

|
|
|
|
10-12-2004, 03:16 AM
|
#5
|
|
Senior Member
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897
Rep:
|
I like this!
But you're (unknowingly) pointing at something I've always wondered: If you write a sed rule like 's|(\something\)|\1 something|g' (note that something is *after* the \1, and the 'g' option), is there a risk on any platform, that sed will apply the same rule to the something that is after \1? Or will parsing go on with what is after the initial \(something\) consistently on all platforms?
In short, is there a risk to write a rule that will infinitely recurse?
Yves.
|
|
|
|
10-12-2004, 04:30 AM
|
#6
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
Well, If such a bug existed, it would have manifested itself since 1978, where the first sed was made available (Unix version 7), and I'm not aware of that.
Another side note, both my answer and yours are in fact non portable, as they use a gnu extension allowing \n to be present in the replacement string.
With standard Unix sed, one should use something like:
Code:
echo "$URL" | sed 's/./&\^J/g'
Where ^J is a real newline, entered as is or with the sequence control-V control-J.
PS: Il fait beau à Rennes ?
|
|
|
|
10-12-2004, 07:21 AM
|
#7
|
|
Senior Member
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897
Rep:
|
Hi! Weather's changing from bright sunshine to heavy rain, and back, every 10 minutes! But à Rennes, je ne sais pas...
I'm very interested in that last bit (not the weather, the ^J  )
How did you know control-V control-J would do that?
Yves.
|
|
|
|
10-12-2004, 12:23 PM
|
#8
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
Je suis tombé dedans quand j'étais petit ...
|
|
|
|
10-13-2004, 02:59 AM
|
#9
|
|
Senior Member
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897
Rep:
|
Ah... OK. (non French people: he fell into Unix when he still was a kid, reference to Obelix in the Asterix books)
Is there a man or web page where I could drink some of this magic knowledge?
|
|
|
|
10-13-2004, 03:23 AM
|
#10
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
man vi:
^V: quote non-printable character
man ksh/bash:
set -o
vi Use a vi-style command line editing interface.
Yes you have to read between the lines to know all of that ...
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:09 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|