Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

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
0
David Allen
Asked:
David Allen
  • 3
1 Solution
 
ozoCommented:
#!/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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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