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


  Search this Thread
Old 03-13-2007, 06:56 PM   #1
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"?
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, 07:02 PM   #2
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

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

Rep: Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627
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.

Old 03-14-2007, 06:40 AM   #4
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,362

Rep: Reputation: 192Reputation: 192
bash-2.05$ x=xyz12345     
bash-2.05$ echo $x
bash-2.05$ echo ${x#xyz}


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 04:49 PM
processing a ksh shell in bash environment ntoughe Programming 9 09-12-2005 05:09 AM
Bash way to tell if String is in String tongar Programming 3 06-16-2005 06:59 AM
newbe bash question ( grep processing) therealbxp Programming 2 11-20-2004 07:40 AM
BASH string expansions Barbarian Programming 2 11-21-2001 10:40 PM

All times are GMT -5. The time now is 09:00 AM.

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