0
1
This is my actual file WASfile
#!/bin/sh
sed -i '/^ *$/d' WASfile
sed -i -e '/user=/,/group_1=/{w /tmp/1' -e 'd}' /home/wasdm/WASfile;
Script to Add
read -p "Press [Enter] to continue for Installation"
Now, I want to put the following script at Script to Add above and then execute the WASfile as script(which is combination of many scripts or commands).
#!/usr/bin/awk -f
BEGIN { FS="=" }
NR==FNR { a[$1]=$0; next }
$1 in a { $0=a[$1] }
/^#/ { var=$1; sub(/^#/, "", var); if(var in a) { $0=a[var] } }
1
I want to combine and use as below or a better way to combine both the scripts.
#!/bin/sh
sed -i '/^ *$/d' WASfile
sed -i -e '/user=/,/group_1=/{w /tmp/1' -e 'd}' /home/wasdm/WASfile;
#!/usr/bin/awk -f
BEGIN { FS="=" }
NR==FNR { a[$1]=$0; next }
$1 in a { $0=a[$1] }
/^#/ { var=$1; sub(/^#/, "", var); if(var in a) { $0=a[var] } }
1
read -p "Press [Enter] to continue for Installation"
I am unable to execute the Script.
So, I tried to extract the AWKscript to another file and try to execute that AWKscript. But, the problem is after extracting, the main script WASfile itself breaks or fails.
#!/bin/sh
sed -i '/^ *$/d' WASfile;
sed -i -e '/\/usr\/bin\/awk/,/baba/{w 1' -e 'd}' WASfile;
#!/usr/bin/awk -f
BEGIN { FS="=" } NR==FNR { a[$1]=$0; next } $1 in a { $0=a[$1] } /^#/ { var=$1; sub(/^#/, "", var); if(var in a) { $0=a[var] } } 1
baba
read -p "Press [Enter] to continue for Installation"
as below
#./WASfile
sed: -e expression #1, char 24: missing command
./WASfile: line 6: BEGIN: command not found
./WASfile: line 7: {: command not found
./WASfile: line 7: next: command not found
./WASfile: line 8: in: command not found
./WASfile: line 9: syntax error near unexpected token `/^#/,'
./WASfile: line 9: `/^#/ { var=$1; sub(/^#/, "", var); if(var in a) { $0=a[var] } } '
You describe that the first script is stored inside a file called
WASfile
but in the same script you are editing a file of the same name twice (WASfile
and with a full path/home/wasadm/WASfile
). Is it supposed to be the same file and do you really want to create a self-modifying code? Or did you just unpractically used the same name for the script and for the file being edited? --- I would strongly discourage you from the self-modifying code. You will need much more knowledge to make it working correctly. – pabouk – 2013-11-18T09:48:36.727