LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-27-2004, 12:47 AM   #1
kubicon
Member
 
Registered: Aug 2003
Location: Limbo
Posts: 54

Rep: Reputation: 15
spliting a simple string


I'm writing a sell script.
What quick function/program can I use to split a string of the form
user@domain.tld
I need to use command substitution, e.g. `program user@domain.tld`

I want to have 2 variables. One with value 'user' and the other one with 'domain.tld' . In other words, I want to split using the '@'


thanks
 
Old 02-27-2004, 04:10 AM   #2
paragon17
LQ Newbie
 
Registered: Feb 2004
Distribution: Mandrake 7.2
Posts: 19

Rep: Reputation: 0
the perl function, split
will do what you want.

split(_1, '@')

are you using '/bin/sh' script or '/bin/bash' (or another shell?)
think that from bash you can access strstr, which will give you
the point in the string where the '@' char is. then you can easily
extract the parts you want.

Sorry if my answer is vague. There are many tutorials for bash
and for perl on the web, all of which should show you how to
do this sort of thing.

Paragon
 
Old 02-27-2004, 04:11 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
You could use awk (among others) to do the job. Awk needs to know what the seperator is (standard space/tab), you can do that with awk's -F option.

echo "user@domain.tld" | awk -F"@" '{ print $1, $2 }'

$1 holds user, $2 holds domain.ltd

Hope this gets you going again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple C++ string questioin, i hope Ha1f Programming 2 10-12-2005 08:23 PM
Simple bash script help, grabbing part of a string colabus Linux - Newbie 3 04-25-2005 09:42 AM
Replace a string including simple quotes. philipina Programming 4 03-18-2004 08:01 AM
simple C string question mvendramini Programming 9 09-30-2003 07:05 PM
Trying to build simple app to notify about changes in small string... Help? Mamour Programming 5 08-23-2003 03:05 PM


All times are GMT -5. The time now is 11:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration