[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Bourne shell to move a file containing certain text

Posted on 2010-11-15
4
Medium Priority
?
285 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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,…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

649 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