Help answer threads with 0 replies.
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, 07: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, 08:02 PM   #2
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

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

Rep: Reputation: 744Reputation: 744Reputation: 744Reputation: 744Reputation: 744Reputation: 744Reputation: 744
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, 07:40 AM   #4
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 200Reputation: 200Reputation: 200
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 16 10-18-2017 04:12 AM
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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:44 PM.

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