copy files containing specific words in a specified line
Anyone knows how to use bash script to copy / move files containing particular words in a specified line to other folders?
for example: lots of text files *.txt in a folder /tmp I'd like to move files containing "my book" in the line 9 to another folder /home/abenmao/my book/, and move files containing a word "my dog" in the line 9 to another folder /home/abenmao/my dog/ ... Thank you for looking into my question |
grep with the -l switch will list only the file names. Test it first:
Code:
grep -l "my book" * Code:
cp `grep -l "my book" *` /home/abenmao/mybook/ |
A requirement is "pattern in line 9". I would keep it simple and use a loop like this:
Code:
#!/bin/bash |
ehh.. missed the line-9 requirement. Your script is pretty neat.
|
thanks,colucix, your code worked like a charm. thanks a million! linux is really really powerful. a very long way for me to go!
|
never expect my question will be answered in such a short time. thanks
Quote:
|
All times are GMT -5. The time now is 07:52 AM. |