• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Bourne shell to move a file containing certain text

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 Allen
David Allen
  • 3
1 Solution
cd /specific/directory
mv `grep -l -- "$1" *` $2
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.
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!

David AllenSelf EmployedAuthor Commented:
(See last comment by me added to question)
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.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now