1752340 Members
5727 Online
108787 Solutions
New Discussion юеВ

Re: string manipulation

 
shellProgramming
New Member

string manipulation

How can I change
"Show 2008 -201" to "Show 2008-201"?
Basically, how can I remove the space before the "-".
Thank you
5 REPLIES 5
Tim Nelson
Honored Contributor

Re: string manipulation

Hello shellProgramming,

Welcome to the HPUX Forums.

There are 100s of ways.

Here is one.

echo "Show 2008 -201"|sed -e s/\ -/-/g


James R. Ferguson
Acclaimed Contributor

Re: string manipulation

Hi:

While I would use 'sed' (or Perl) for the transformation you show, if you want to use pure shell, you can do:

# echo Show 2008 -201|read A B C;echo "${A} ${B}${C}"

Regards!

...JRF...
Chris Vail
Honored Contributor

Re: string manipulation

In Shell programming there are always a lot of ways to do anything. Here's a way to do it in awk:
echo "Show 2008 -201"|awk -F" " '{ print $1" "$2$3 }
Ivan Krastev
Honored Contributor

Re: string manipulation

And one more (with search and replace):

echo "Show 2008 -201" | awk '{sub(/ -/,"-");print}'


regards,
ivan
shellProgramming
New Member

Re: string manipulation

Thank you all