[SOLVED] bash script trying to remove a leading ' and a tailing '
ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
bash script trying to remove a leading ' and a tailing '
I have a script that calls for a file description on a core file. I then pull the name of the process that caused the core file.
unfortunately, the process name is pulled with a leading ' amd a tailing'. I would like to remove the leading char and the last char.
Olion's version above works only if you can be sure that the ' will not appear anywhere else in the string, as it simply removes any and all marks it finds. But here again parameter substitution can do it faster and more efficiently than piping it through an external tool.
Code:
VAR="${VAR//\'}"
Otherwise, Catkin's version is probably the best, for the same reasons.
I have a script that calls for a file description on a core file. I then pull the name of the process that caused the core file.
unfortunately, the process name is pulled with a leading ' amd a tailing'. I would like to remove the leading char and the last char.
I tried sed, but it seems to not like using the special char '.
I second the suggested solutions that use parameter substitution in BASH, anyway using sed you can do
Code:
echo $VAR | sed "s/'//g"
as you can see, using single quotes to embed the sed command is not mandatory. In this case you have to protect the single quote from bash and double quotes perform their job perfectly.
I second the suggested solutions that use parameter substitution in BASH, anyway using sed you can do
Code:
echo $VAR | sed "s/'//g"
as you can see, using single quotes to embed the sed command is not mandatory. In this case you have to protect the single quote from bash and double quotes perform their job perfectly.
Thank you.
And for last word on the line:
$ cat x
ProcessName: 'Process'
$ sed "s/ '\([^ ][^ ]*\)' *$/ \1/" x
ProcessName: Process
$
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.