Bourne shell to move a file containing certain text

Hi!
I need to write a bourne shell file (to be executed by an application). I am very rusty on Bourne shell and don't know how to start what I want to do.
I need to pass the bourne shell a couple of text strings (so that they becomes $1 and $2 in the shell). I then want the shell program to cd to a specific directory and look for the files in there to find the one that has the text in $1. (If everything is working properly, there will be only one file in there with that string in it.) Having found the file , I then need to move that file to a different directory and rename it to the name in $2 (thereby removing it from the original directory.

Can you give me a start on how to do this?

Thanks in advance
David AllenSelf EmployedAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
#!/bin/sh
cd /specific/directory
mv `grep -l -- "$1" *` $2
0
 
David AllenSelf EmployedAuthor Commented:
Thanks for the quick reply!
That looks promising! I'll test it out and let you know how I get on.
0
 
David AllenSelf EmployedAuthor Commented:
Yes it does work!

I had a feeling it might be straightforward, and when you showed me the method, it made sense. But it would have taken me a long time to work out!

Thanks
0
 
David AllenSelf EmployedAuthor Commented:
(See last comment by me added to question)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.