Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-12-2004, 12:58 PM   #1
LQ Newbie
Registered: Jun 2004
Location: UK
Distribution: SuSE
Posts: 10

Rep: Reputation: 0
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`
find ./ -name $file | xargs grep -l 'Mystring'

- it outputs nice stuff like


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?
Old 10-12-2004, 02:56 PM   #2
LQ Newbie
Registered: Sep 2004
Location: Cheshire, UK
Distribution: Mandrake
Posts: 17

Rep: Reputation: 0
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

Old 10-13-2004, 03:40 AM   #3
Senior Member
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
vi $(for file in `cat filelist`; do find . -name "$file" -exec grep -l 'Mystring' {} \; ; done)
Old 10-14-2004, 12:04 AM   #4
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
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.

./g | sed -f fixup.sed
Keep in mind that you might need the -n sed option also.
Old 10-14-2004, 12:31 AM   #5
Senior Member
Registered: Dec 2001
Location: 35.7480 N, 95.3690 W
Distribution: Debian, Gentoo, Red Hat, Solaris
Posts: 2,070

Rep: Reputation: 47
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.
Old 10-14-2004, 01:58 AM   #6
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,592

Rep: Reputation: 2435Reputation: 2435Reputation: 2435Reputation: 2435Reputation: 2435Reputation: 2435Reputation: 2435Reputation: 2435Reputation: 2435Reputation: 2435Reputation: 2435
You can capture the output of the scritp to eg t.t, then use
:r t.t
to insert the contents.
Old 10-14-2004, 04:40 AM   #7
LQ Newbie
Registered: Jun 2004
Location: UK
Distribution: SuSE
Posts: 10

Original Poster
Rep: Reputation: 0
Well, thanks for all the answers, I went for the theYinYeti's response which does the job nicely.

Thank you all


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 07:07 PM
BASH Shell script : copying a file to multiple folder zamri Programming 14 04-29-2008 11:27 AM
script #!/bin/bash, problem with space in file names existent Linux - General 3 06-17-2004 09:13 AM
Bash crashes ? File names with () and spaces Danodare Slackware 1 02-27-2004 03:50 PM
Putting Script Names In Shell Scripts sayble96 Linux - Newbie 4 12-17-2003 11:16 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:00 PM.

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