Move the files which is coming after grepping


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Move the files which is coming after grepping
# 1  
Old 04-23-2013
Move the files which is coming after grepping

Dear Friends,

I am trying to move the files which are listing after greaping command.

see the details below
1. When i am running the grep command

Code:
$  grep -il 'Bufman' *.*
fatal.log
fatal_info.log

it has listed some files now i want to move this files to any another locate so i am trying to write this following command which is not working at all

Code:
mv ' grep -il 'Bufman' ~/finacle/RIPU/*' ../MARK/.

Pls help.

Ripudaman Singh

---------- Post updated at 04:23 AM ---------- Previous update was at 04:19 AM ----------

i want to move the files with the grep command only.
# 2  
Old 04-23-2013
Code:
mv `grep -il Bufman ~/finacle/RIPU/*` ../MARK/

Or, using $ () instead of old backticks:
Code:
mv $(grep -il Bufman ~/finacle/RIPU/*) ../MARK/

If there are a whole bunch (MANY) files to move, and the command length is exceeeded, you would need to use xargs.
# 3  
Old 04-23-2013
It didnt worked.
$ mv `grep -il Bufman /finacle/RIPU/*' ../MARK/.
>
$ mv $(grep -il Bufman /finacle/RIPU/*) ../MARK/.
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2

---------- Post updated at 05:40 AM ---------- Previous update was at 05:34 AM ----------

$ mv `grep -il 'Bufman' *.*` ../MARK/
mv: fatal.log and ../MARK//fatal.log are identical
mv: fatalinfo.log and ../MARK//fatalinfo.log are identical
# 4  
Old 04-23-2013
try in a loop

Code:
grep -il Bufman *.* | while read file
do
echo "Moving $file"
mv $file ../MARK/
done

# 5  
Old 04-23-2013
For the first case:
Code:
mv `grep -il Bufman /finacle/RIPU/*' ../MARK/

vs the correct form with backtick instead of quote:
Code:
mv `grep -il Bufman /finacle/RIPU/*` ../MARK/

-----------------------
But the backticks or $() are the same, and the second form does not work there, so something else is going on. What does the following produce:
Code:
grep -il Bufman /finacle/RIPU/*

../MARK/ depends on the directory you are in when you enter the command, so that is a likely cause. Use an absolute path like /finacle/MARK/ path.
# 6  
Old 04-23-2013
./1.sh[2]: --start: Cannot find or open the file.
Moving 1.sh
mv: 1.sh and ../MARK//1.sh are identical
Moving fatal.log
mv: fatal.log and ../MARK//fatal.log are identical
./1.sh[7]: Syntax error at line 8 : `newline or ;' is not expected.
# 7  
Old 04-23-2013
What does the following produce? If it's a lot of files, show a representative sample.
Code:
grep -il Bufman /finacle/RIPU/*

In your script, change ../MARK/ to an absolute path.

Where might --start come from? Figure that out, and you might get somewhere.

Show your current script. And do not type by hand. Copy and paste. And use those code tags. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies

2. Shell Programming and Scripting

Performance issue in Grepping large files

I have around 300 files(*.rdf,*.fmb,*.pll,*.ctl,*.sh,*.sql,*.prog) which are of large size. Around 8000 keywords(which will be in the file $keywordfile) needed to be searched inside those files. If a keyword is found in a file..I have to insert the filename,extension,catagoery,keyword,occurrence... (8 Replies)
Discussion started by: millan
8 Replies

3. Shell Programming and Scripting

Grepping large list of files

Hi All, I need help to know the exact command when I grep large list of files. Either using ls or find command. However I do not want to find in the subdirectories as the number of subdirectories are not fixed. How do I achieve that. I want something like this: find ./ -name "MYFILE*.txt"... (2 Replies)
Discussion started by: angshuman
2 Replies

4. Shell Programming and Scripting

grepping files and then renaming file

Hi, What is the easiest way to list a directory with 1000s of filenames, grep it for a certain sequence of numbers, and if found to rename the file by the value you are grepping. eg The file I am examining will looks like this: 1234 1224343 2324 244 35665 If I am examining a list... (1 Reply)
Discussion started by: mantis
1 Replies

5. UNIX for Dummies Questions & Answers

grepping log files

I have a log file and I have two unique strings which represent the start and end of the text I want to obtain. How can I get all the text inbetween this start string and the end string? Thanks (2 Replies)
Discussion started by: chrisjones
2 Replies

6. Shell Programming and Scripting

Files are not coming in attachement by any command

Hi All I want to send a file thru a mail with an attachment. i tried using uuencode , but it says "bash: uuencode: command not found" and the same i am getting for mutt as well: "bash: mutt: command not found" Tried searching in all the forums but could not find anything... (2 Replies)
Discussion started by: Prateek007
2 Replies

7. UNIX for Dummies Questions & Answers

grepping between files

Hi I have two files File 1 alias HOME =.. alias DATA = ${DATA}/runtime1/test alias SQL = ${DATA}/find1dir/test alias SQL1 = ${HOME}/sql/orcl alias SQL2 =... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

8. Shell Programming and Scripting

awking and grepping parts of files: the 'super diff'

OKAY---- Here's what I must do. I have two files. I need to compare the two files such as with the diff command. I am adding FILENEW to FILEOLD If fields $1, $2, $5, and 6 are the same, then I don't want to add FILENEW records to FILEOLD. If they are not, then append the lines. Is... (11 Replies)
Discussion started by: jeffpas
11 Replies

9. Shell Programming and Scripting

grepping many values from same files

Hi All, I am having a script in which I am greping some values and storing them from files with .err and .log extensions. I feel I can do it better.But How? Below is my piece of code. oneerrors=`egrep -i -n "one" *.err *.log` twoerrors=`egrep -i -n "two" *.err *.log` ... (2 Replies)
Discussion started by: Sreejith_VK
2 Replies

10. UNIX for Advanced & Expert Users

grepping lines out of files

Hi, I wonder if anyone can help me. I have a file with about 200 lines in it. I am wanting to set up a Count so that it picks out each line at turn and edits the line. However i am having trouble pulling out the specific line. I have a feeling it will be done somehow by a grep -n but what ever i... (2 Replies)
Discussion started by: mariner
2 Replies
Login or Register to Ask a Question