LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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



Reply
 
Search this Thread
Old 03-13-2007, 07:56 PM   #1
powah
Member
 
Registered: Mar 2005
Distribution: FC, Gentoo
Posts: 276

Rep: Reputation: 30
bash string processing


If the bash input parameter $1 is in the format "xyznnnnn", where "xyz" is fixed and "nnnnn" can be varied, how to extract the remaining of the string "nnnnn"?
e.g.
If input is "xyzabc", then extracted string should be "abc".
If input is "xyz12345678", then extracted string should be "12345678".
Thanks in advance.
 
Old 03-13-2007, 08:02 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
you can read about bash string processing here
 
Old 03-14-2007, 07:13 AM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,236

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
stripped_string=$(echo $1 | sed s/xyz//)

This is what I could do without looking it up in the Bash guide. Bash also has string functions. Take a look at the guide as pointed to in my signature.

jlinkels
 
Old 03-14-2007, 07:40 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
Code:
bash-2.05$ x=xyz12345     
bash-2.05$ echo $x
xyz12345
bash-2.05$ echo ${x#xyz}
12345
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
processing command args in bash slzckboy Programming 10 09-28-2005 05:49 PM
processing a ksh shell in bash environment ntoughe Programming 9 09-12-2005 06:09 AM
Bash way to tell if String is in String tongar Programming 3 06-16-2005 07:59 AM
newbe bash question ( grep processing) therealbxp Programming 2 11-20-2004 08:40 AM
BASH string expansions Barbarian Programming 2 11-21-2001 11:40 PM


All times are GMT -5. The time now is 08:59 PM.

Main Menu
Advertisement
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