Hi,, Please excuse my lack of knowledge here. I think I am tring to do something fairly advanced yet am a bit of a beginner.....
I want to use a korn shell (as is the norm with others in my company) to write a script to search a file for a string and insert some text above that line.
Sudo code as follows:
User inputs data item 1
User inputs data item 2
Search commands file for 'end of commands' marker
Insert new command above the line in the format 'command $data1 $data2 true'
I have seen notes on awk and sed but cannot seem to get any output when attempting to run these from the command line.
I already have the script to capture the user data.
Please help
Thanks in advance
Hugo
To be honest, not a lot, I tried simply substituting the text I am searching for from the command line as follows:
$ sed -f hugo01.vm1.commands 's/oldtext/newtext/'
but got the error
sed: file hugo01.vm1.commands line 1: unknown option to `s'
...just to test if I could sustitute the 'end of commands' marker with a new line and put the marker back in as a partial solution
Here is an obfuscated awk based solution:
pc pbzznaqf_svyr /gzc/pbzznaqf_svyr
njx -i q1="$qngn1" -i q2="$qngn2" '/raq bs pbzznaqf/{cevag "pbzznaq",q1,q2,"gehr"}1' /gzc/pbzznaqf_svyr > pbzznaqf_svyr
rot13.com
Not tested.
It can be almost as easily done entirely whith ksh built in commands if you are inclined to do so.
ok I have this inside my script now, which displays my output to the screen with 'test' in the right place:
awk '/#end of nero56 commands/ {print "test"} {print}' hugo01.vm1.commands > hugo01.vm1.commands
how would I write this to a file? I tried adding a '> newfile' on the end but I got permission denied
process_the_file a_file > a_file
This is a common error, it cannot work since the shell evaluates > a_file before to start the command, therefore a_file is emptied before any work.