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? |
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 |
Code:
vi $(for file in `cat filelist`; do find . -name "$file" -exec grep -l 'Mystring' {} \; ; done) |
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 |
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.
|
You can capture the output of the scritp to eg t.t, then use
:r t.t to insert the contents. |
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. |