?
Solved

Bourne shell to move a file containing certain text

Posted on 2010-11-15
4
Medium Priority
?
284 Views
Last Modified: 2012-05-10
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
Comment
Question by:David Allen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 34135127
#!/bin/sh
cd /specific/directory
mv `grep -l -- "$1" *` $2
0
 

Author Comment

by:David Allen
ID: 34135137
Thanks for the quick reply!
That looks promising! I'll test it out and let you know how I get on.
0
 

Author Comment

by:David Allen
ID: 34135188
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
 

Author Closing Comment

by:David Allen
ID: 34135193
(See last comment by me added to question)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question