This is a discussion on Need help on moving files and something else within the Shell scripting forums, part of the Development/Scripting category; I need some files to be copied to a different folder. But I have to setup a script which downloads ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
I need some files to be copied to a different folder. But I have to setup a script which downloads a file called file.zip but the problem is that this file is extracted every time to a folder with different name. I think this file is updated weekly and and then folder in which files are extracted is for example
file01082006 then next time I download the file and extract it folder would be named file08082005. Now is there a way for me to copy all files in that folder to another location. It contains like 50 txt files. Can I somehow use a wildcard like file* or something. Or can I specify names of text files to be copied and can they be found even if I don't specify exact folder name? I need content of this folder, these text files moved to another location since I want to include them in a web page. So I don't need the folder iteslf copied. Maybe if there is a way to copy all files from specified folder and subfolders to another folder. So I could extract this zip to for example /root/folder/file01082006/*.txt and if possible copy all files from "folder" to a different location. And another thing I could use a help with is, is there some command or more of them I could use to insert two words at the very beginning and the end of those files. Like to insert "start" and "end" in each file. Thank you in advance, I hope my question is understandable. I am a beginner and English is not my native language. |
| Sponsored Links | ||
|
|
|
|||
|
I noticed they all have same word at the top of the file so I could use sed to replace it with what I need. But I still need a way to insert the other one at the end. I need text wrapped in <pre> tags. So I could replace first word in document with <pre> but I still need a way to insert </pre> at the end. And the way to copy them without specifing exact path.
|
|
|||
|
Thanks monk.
This line: Code:
cp head.txt filename.txt tail.txt > /tmp/final.txt and use echo to add </pre> at the end. It would help if I could use wildcards to cover all files at once, but I don't think that is possible. I guess I can use wildcard for sed input but I can't for output. And I tried using wild card with echo but it gave me: Code:
ambiguous redirect |
|
||||
|
karabaja, i am sorry it should be cat and not the cp i.e. line should be:
Code:
cat head.txt filename.txt tail.txt > /tmp/final.txt Code:
files="ls /data/*.txt" echo '<pre>' > /tmp/head echo '</pre>' > /tmp/tail for i in $files do out="/tmp/out.$$" cat /tmp/head $i /tmp/tail > $out cp $out $i rm -f $out done rm -f /tmp/head /tmp/tail Try out and lemme know |
|
|||
|
Thx but I've already written a script with your first echo suggestion. Although I did it the hard way but as long as it is done and working now.
I had to write like 150 lines for echo command to insert in </pre> in each file and then 150 lines with sed command to replace first word with <pre> and to output result to destination folder when I need them But it did just what I need, that's what matters, thx. P.S. That last code works fine. I just wish I've waited some more for before doing it the hard way. But never mind, I needed that first word removed anyway. I'd still have to use sed or something else to remove it. |
|
||||
|
You can use grep to remove exact word, for example remove word <pre>:
Code:
egrep -wv '<pre>' input.txt > output.txt Code:
sed -e '1s/<pre>//' input.txt > output.txt Code:
sed -e 's/<pre>//g' input.txt > output.txt |
|
|||
|
Thx guys for all the help.
Now I am just curious even though I don't need this at the moment, but would like to learn. How would reverse process look like. Fore example to grep content of the file.txt but only output what is between "start" and "end" in that file, not the whole content. And what would happen if "start" and "end" would appear more then once in the document. Sorry to keep bugging you guys but when I try to find out more about some command on the net all I get is basic usage. |
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell script for automatic conversion of files in tar files | kasimani | Shell scripting | 2 | 02-08-2007 04:45 PM |
| moving files based on size | kavi | Shell scripting | 2 | 11-11-2005 06:17 PM |