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
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?
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.
Summary: Best choice would be for that file to have something besides spaces for the field delimeters (comma, semicolon, bar character). Your only problem right now is with spaces in phone number, but what if...
Summary: Dear Forum, I'm trying to write a script that will check to see if a new file has been written to our server, and if so, execute a procedure in Oracle using sql*plus to upload the new file. It's impo...
Summary: I need to read a specific part of an input file and assign the data as variables until it reaches the "END". So, for captain coke, I need rum, 2, coke, and 4 as seperate variables. I realize that I s...