LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash:output file names from shell script to vi (https://www.linuxquestions.org/questions/linux-newbie-8/bash-output-file-names-from-shell-script-to-vi-241765/)

sickboy 10-12-2004 11:58 AM

bash:output file names from shell script to vi
 
I'm using SuSE 8 ES and am new to shell scripting and have created a script to locate certain files and output their relative path and filename. It works well, my script is called g -

for file in `cat filelist`
do
find ./ -name $file | xargs grep -l 'Mystring'
done

- it outputs nice stuff like

./WEB-INF/templates/xsl/rcu/browser/edit.xsl
./WEB-INF/templates/xsl/rcu/browser/custom.js
./WEB-INF/templates/xsl/rcu/browser/custom2.js
.
.
.

I now want to output these filenames into vi to do a multiple edit so I do -

./g | xargs vi

this does some strange stuff, vi behaves 'funny' like it lets me :n round the files but then when I go back with :e# they aren't there plus when I quit vi my terminal session is totally messed up with double-echoed prompts etc


Any ideas on how I can tidy this up?

f0ul_Oli 10-12-2004 01:56 PM

Why not just put all the info you want into a txt file first, and then open VI?

shell name >> textfile

I can't see why it shouldn't work but I'm sure if it doesn't - someone will tell me!

hope this helps

F0ul

theYinYeti 10-13-2004 02:40 AM

Code:

vi $(for file in `cat filelist`; do find . -name "$file" -exec grep -l 'Mystring' {} \; ; done)
Yves.

jschiwal 10-13-2004 11:04 PM

If you always perform the same edits, you might want to write a sed script to do the job rather than vi.

Then you could pipe it through sed on the same line.

Code:

./g | sed -f fixup.sed
Keep in mind that you might need the -n sed option also.

darthtux 10-13-2004 11:31 PM

I would put it in a script but this question is killing me. If you have a script, if you do a !script in vi it show the output on the screen. There has to be a vi command to take the output of a script/command and insert it at the end of the current cursor position. It seems like i have heard of it but can't locate it at the moment.

chrism01 10-14-2004 12:58 AM

You can capture the output of the scritp to eg t.t, then use
:r t.t
to insert the contents.

sickboy 10-14-2004 03:40 AM

Well, thanks for all the answers, I went for the theYinYeti's response which does the job nicely.

Thank you all


All times are GMT -5. The time now is 01:12 PM.