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.
use vi within script?
Name: numassa Date: November 20, 2006 at 06:29:49 Pacific OS: Linux Red Hat CPU/Ram: 2/1 Product: Sony
Comment:
Hi, I'm very new to unix/linux and was wondering if you could edit a text file from within a script. e.g if I ran... sh scriptname test
Then, the script would insert the word 'test' into the file at a predetermined point e.g after the first line.
Apologies if this is already covered somewhere I did search. Thanks
Although it's not commonly done, you can call vi within a script using the unix "here" document:
#!/bin/ksh
text="test" vi myfile << MSG o$(printf "%s" "$text") $(echo '\033'):wq MSG # end script
All the keystrokes after vi'ing the file go within the here document - open the line below line 1, enter the string with printf, press the escape key, write and quit. I don't care for it myself.
0
Response Number 4
Name: Dlonra Date: November 20, 2006 at 17:28:49 Pacific
Reply:
I have created simple to complex editing scripts using ex. I generally put the scripts into a file. ex myfile < myscript
ex is preferred to vi because using vi in a script results in strange stuff on your terminal.
0
Response Number 5
Name: numassa Date: November 21, 2006 at 03:40:13 Pacific
Reply:
Thanks to everyone that replied. I went with the 'sed' method but the other replys look interesting and I shall look at them further in the future. Thanks for all your help
0
Response Number 6
Name: nails Date: November 21, 2006 at 11:14:54 Pacific
Reply:
If vi's output is causing you problems, simply send it to /dev/null:
Summary: Security transferred our KORN shell scripts from our server running Linux to another server running NT so they could run a virus scan program against them. Then they copied our scripts back and none ...
Summary: Hi all, Please forgive me if you saw this post in other forums as well. I just do not seem to get any answer.... A. My Environment ============== I am using RedHat Linux, version 2.6.18-53.el5. When I...
Summary: hi it seems to me that mktime() needs a c library now i m using bourne shell scripting #!/bin/sh i hav googled it a lot but cant find out the exactly how to use mktime(awk scripting using sh) in co...