Computing.Net > Forums > Unix > Korn shell value replacement

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Korn shell value replacement

Reply to Message Icon

Name: jcarrott
Date: March 27, 2009 at 07:18:47 Pacific
OS: AIX UNIX
Subcategory: Software Problems
Comment:

The line of text that I am trying to use is -
sed 's/flag1/$cnumber' $header > $header
I have a document (header) with place holders flag1, flag2, flag3, etc. I want to replace the place holder with the value of $cnumber.
The error I get is "sed: 0602-404 function s/flag1/$cnumber cannot be parsed.
The file "header" looks like
{{Begin}}
{{Company flag1}}
{{Winsecid LAWSON_FAX}}
{{Contact flag2}}
{{Endcovertext}}
{{Fax flag3}}
Can somebody tell what I am doing wrong?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 27, 2009 at 08:36:50 Pacific
Reply:

This link shows how to embed shell variables in sed commands:

http://www.computing.net/answers/pr...


0

Response Number 2
Name: jcarrott
Date: March 27, 2009 at 09:00:17 Pacific
Reply:

I must be doing something wrong. I tried enclosing the value in single and double quotes, double and single quotes, single quotes, and finally double quotes.

sed -e 's/flag1/"'$cnumber'"/' $header > $header.txt

None of it seems to work.


0

Response Number 3
Name: nails
Date: March 27, 2009 at 09:18:34 Pacific
Reply:

It works on my Solaris 9 box:

#!/bin/ksh

cnumber=myflag
sed -e 's/flag1/'"${cnumber}"'/' header > header.txt


0

Response Number 4
Name: jcarrott
Date: March 27, 2009 at 11:05:04 Pacific
Reply:

Thank you for the help. I will check with operations for our AIX box. There has to be something a little different.


0

Response Number 5
Name: thepubba1
Date: April 5, 2009 at 19:31:33 Pacific
Reply:

sed 's/flag1/$cnumber' $header > $header

The first problem is redirecting to the file you are reading from clobbers your input file.

Try this:

header=header
cnumber=10

sed -e "s/flag1/"${cnumber}"/" $header > header1

Your header file before:

{{Begin}}
{{Company flag1}}
{{Winsecid LAWSON_FAX}}
{{Contact flag2}}
{{Endcovertext}}
{{Fax flag3}}


Your header file after:

{{Begin}}
{{Company 10}}
{{Winsecid LAWSON_FAX}}
{{Contact flag2}}
{{Endcovertext}}
{{Fax flag3}}

Tested on AIX


0

Related Posts

See More



Response Number 6
Name: jcarrott
Date: April 6, 2009 at 06:16:59 Pacific
Reply:

Thank you - that worked.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Code to install new print... Unix sort - left to right


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Korn shell value replacement

escaping * in korn shell www.computing.net/answers/unix/escaping-in-korn-shell/7016.html

korn shell help www.computing.net/answers/unix/korn-shell-help/7834.html

korn shell help please www.computing.net/answers/unix/korn-shell-help-please/4364.html