Computing.Net > Forums > Unix > Substring after =

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Substring after =

Reply to Message Icon

Name: bvsbabu
Date: September 26, 2006 at 08:07:16 Pacific
OS: KSH
CPU/Ram: ksh
Product: AIX
Comment:

Hi,

I have a string called name1=value1.
I am struggling to write a awk/script to get the "value1" into some variable. Could some one help me... plzzzzz




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 26, 2006 at 08:50:14 Pacific
Reply:

Any number of unix tools can solve this problem:

#!/bin/ksh

myvar=$(echo "name1=value1"|awk ' BEGIN { FS="=" } { print $2 } ')
echo $myvar

You can use the ksh pattern matching operators to do the same thing:

var="name1=value1"
x=${var#*=}
echo $x

In the above example, anything and an equal sign is deleted from the string.



0

Response Number 2
Name: bvsbabu
Date: September 26, 2006 at 09:01:12 Pacific
Reply:

Thank you very much for your help.. it helped me very much.

I have extension of this problem, I need to search in a file config.xml for <user>scott</user> and replace the value "scott" with different value "xyz". The final output of the config.xml is <user>xyz</user>

Is there any way to search and replace in the config.xml without renaming it.


0

Response Number 3
Name: nails
Date: September 26, 2006 at 12:58:01 Pacific
Reply:

When using the traditional unix tools such as awk, sed, tr, etc. you have no option but to rename the file after processing finishes.

I'm not much of a perl programmer, but I know that perl has an option that allows editing a file without renaming it.

Perhaps some of the other modern scripting languages like php and ruby do the same?


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


UNIX Certification Shared Libraries with the...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Substring after =

IF condition after substr www.computing.net/answers/unix/if-condition-after-substr/4000.html

Unix-sed- need help www.computing.net/answers/unix/unixsed-need-help/6647.html

chmod after ftp a file www.computing.net/answers/unix/chmod-after-ftp-a-file/4575.html