LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 08-20-2006, 08:02 PM   #1
thepimpturtle89
LQ Newbie
 
Registered: Aug 2006
Posts: 2

Rep: Reputation: 0
shell script help (vim)


I am trying to write a shell script that will paste a named buffer to many files. a very simple script to prove my problem is this:

The Shell Script
-----------------------------------------------
#!/bin/bash

vim -e -s file.htm < change

exit
-----------------------------------------------
The file with vim commands (file name being "change")
-----------------------------------------------
pu a

x
-----------------------------------------------

I am, of course, trying to paste buffer 'a' into the file named "file.htm". however, when i open the file "file.htm" no change has taken place. to double check myself I have opened up the file "file.htm" in ex mode and simply typed in the commands "pu a" and "x" manually, and sure enough, it does exactly what i want it to do. however, I want the shell script to do this for me.

I am simply trying to get the script to paste a line of code into many html files.... so eventually the script will look more like this

The Shell Script
-----------------------------------------------
#!/bin/bash

for file in *.htm; do

vim -e -s $file < change

done

exit
-----------------------------------------------

where hundreds of .htm files will be awaiting their fate. as of yet, no luck. i have even tried changing the file "change" to read this

-----------------------------------------------
norm "ap
x
-----------------------------------------------

thinking that maybe it would work in normal mode... however it does not. hopefully this is a simple fix... i could easily make the code a macro but then i would have to open up every individual file... bleh.

obviously the shell script will do much more, but everything else I want it to do works perfectly. this is the only part I seem to be having trouble with. as i have said, I can manually open up each individual file and paste 'buffer a' in... so i am certain that 'buffer a' holds the contents i wish to paste. why will it work manually, but not in the shell script?

Last edited by thepimpturtle89; 08-20-2006 at 08:32 PM.
 
Old 08-20-2006, 08:40 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,576
Blog Entries: 47

Rep: Reputation: 1402Reputation: 1402Reputation: 1402Reputation: 1402Reputation: 1402Reputation: 1402Reputation: 1402Reputation: 1402Reputation: 1402Reputation: 1402
If I make a vi script file containing the lines
Code:
:pu 9
:wq
and I execute "vim -s script filename" it works (no Ex mode).


where hundreds of .htm files will be awaiting their fate.
Then find, xargs and sed are your friends. I favour rpl since it does have simulation mode etc, etc.
 
Old 08-20-2006, 09:39 PM   #3
thepimpturtle89
LQ Newbie
 
Registered: Aug 2006
Posts: 2

Original Poster
Rep: Reputation: 0
thanks

hey thanks a lot man, ive always said linux communities are amazing. to have someone reply within forty minutes of my question is great. worked perfectly too. funny how it doesn't work in ex mode... maybe my logic is askew though.

Last edited by thepimpturtle89; 08-20-2006 at 11:07 PM.
 
Old 08-20-2006, 10:40 PM   #4
chii-chan
Member
 
Registered: Sep 2003
Location: chikyuu (E103N6)
Distribution: Redhat 8.0 (2.4.25-custom), Fedora Core 1 (2.4.30-custom)
Posts: 357

Rep: Reputation: 30
You can try 'sed' too. Take a look at this thread:
http://www.linuxquestions.org/questi...ghlight=script
 
  


Reply

Tags
vim


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I made a shortcut to a shell script and it is using default shell icon... shlinux Linux - Software 2 04-20-2006 06:29 AM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
Vim: run shell command without acknowledgement jrdioko Linux - Software 2 02-25-2006 08:52 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Script for vim (shows members of a struct like VC) Xa! Linux - Newbie 3 03-09-2004 07:17 PM


All times are GMT -5. The time now is 09:53 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration