LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 10-12-2004, 11:58 AM   #1
sickboy
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`
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?
 
Old 10-12-2004, 01:56 PM   #2
f0ul_Oli
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

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

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

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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.
 
Old 10-13-2004, 11:31 PM   #5
darthtux
Senior Member
 
Registered: Dec 2001
Location: 35.7480 N, 95.3690 W
Distribution: Debian, Gentoo, Red Hat, Solaris
Posts: 2,070

Rep: Reputation: 45
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, 12:58 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,301

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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, 03:40 AM   #7
sickboy
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
 
  


Reply


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 51 07-04-2013 08:16 PM
BASH Shell script : copying a file to multiple folder zamri Programming 14 04-29-2008 10:27 AM
script #!/bin/bash, problem with space in file names existent Linux - General 3 06-17-2004 08:13 AM
Bash crashes ? File names with () and spaces Danodare Slackware 1 02-27-2004 02:50 PM
Putting Script Names In Shell Scripts sayble96 Linux - Newbie 4 12-17-2003 10:16 PM


All times are GMT -5. The time now is 09:59 AM.

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 Google+: linuxquestions
Open Source Consulting | Domain Registration