Computing.Net > Forums > Unix > ksh - var subs for input file

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.

ksh - var subs for input file

Reply to Message Icon

Name: Rik Bitter
Date: August 20, 2008 at 10:58:45 Pacific
OS: sunos
CPU/Ram: na
Product: na
Comment:

Supppose I had a file that looked like:

See Spot ${verb}
${verb} Spot ${verb}

How would you read the file from a ksh script where verb is defined then output the file with verb's value substituted. Any ideas?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: August 20, 2008 at 20:49:58 Pacific
Reply:

#!/bin/ksh

str="\${verb}"
rep="mystr"
sed -e "s/${str}/${rep}/g" file.txt

The tricky part is escaping the dollar sign to take away the special meaning:

str="\${verb}"


0

Response Number 2
Name: Rik Bitter
Date: August 21, 2008 at 05:20:12 Pacific
Reply:

Thanks for the response. I managed to get around the problem using a similar solution. The problem is that the actual file had several differnt variables in it so every case had to be specifically coded. I was hoping there was a way to get the shell to do the variable substitution for me.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: ksh - var subs for input file

Shell script for Text file parsing www.computing.net/answers/unix/shell-script-for-text-file-parsing/4388.html

Check for new file, exec sql*plus www.computing.net/answers/unix/check-for-new-file-exec-sqlplus/6714.html

read input file variables www.computing.net/answers/unix/read-input-file-variables/5520.html