Copy specific file (different but same name) as folder name
I have to copy a particular file present in a main folder having part of the file-name present in many sub-folders to a new destination preserving the name of the source "part of the main folder" and previous file-name of the output file:
Example:
Can someone give me the command to type under RedHat (csh and bash) please? - Many thanks
Last edited by Don Cragun; 01-20-2015 at 05:00 AM..
Reason: Add CODE tags.
Could you please try following and let me know if this helps.
We can run it as follows by providing 2 arguments first as source file path and second is destination file path as follows.
If you are happy with results above you can run following script then which will copy the files as follows. NOTE: Also if you are happy with results then you can read all the files which you want to copy to a destination directory and pass it to script then.
Kindly use code tags for commands in your posts as per forum rules. Could you please try following and let me know.
After running the script we will get following results.
Could you please let me know what error you are getting while executing it?
Also RSTART and RLENGTH meaning is as follows.
Quote:
RSTART The index of the first character matched by match(); 0 if no match. (This implies that character indices start at one.)
RLENGTH The length of the string matched by match(); -1 if no match.
Thanks,
R. Singh
Last edited by RavinderSingh13; 01-20-2015 at 05:13 AM..
If I'm right, you want to take the second directory in the path and use that as part of the file name in the common target directory.
If you use find to get the list of files and assuming that you can limit the search in some way, (e.g. define source_dirs as a space separated list of directories to search, define name_pattern as an expression, e.g. "*.xxx") you can do the following (in ksh and perhaps bash):-
This may run marginally slower than the awk, but hopefully it shows you what is happening and the logic behind it. I'm using "variable substitution" to slice up the fully qualified file name to get the useful parts and then build the output line at the end.
You haven't said how you generate the list of files, so I've gone with a find command. If you have a file with them all listed, you could just change the loop to be:-
I hope that this helps and that you can follow the logic.
Hi,
Is there a way I can copy a file from a server to a local folder (i.e. My Documents)? can it be done by scp?
I tried this but it just rename the file as the folder it has to be transferred at.
scp -r name@some_server:/home/user/file.txt 'somehere\home\home_dir'
Thanks. (4 Replies)
Hi All,
My requirement is as follows:
A file (say abc) will be having list of the .txt file names. I need to read this abc file line by line and rename the .txt file names inside it and move them to other folder/path.
Eg:
abc
-------
file1.txt
file2.txt
file3.txt
Output (should... (1 Reply)
I need to
"Ensure that when you download libchat.a from the VLE you have copied it to the same folder on ius as your source files. You then refer to the library (and the libraries it needs) with:
gcc -o outputfile sourcefile.c -L. -lchat -lsocket -lnsl"
But I have no idea what this means! (I... (2 Replies)
Hi all...
Below is what I am trying to do:
1. Having the following folder with the files...
/source_folder/dodiddone.tar.gz
/source_folder/gowentgone.tar.gz
/source_folder/gowentgone.log
2. I need to copy and chown files with extension .tar.gz to another folder
copy... (1 Reply)
#!/bin/bash
for i in {1..1536..1}
do
#find /home/test/Desktop/up111/workplace/Malware/$i/logs
for a in /home/test/Desktop/up111/workplace/Malware/$i/logs/*
do
#max=a
for b in /home/test/Desktop/up111/workplace/Malware/$i/logs/*
do
... (4 Replies)
hye there...
i have a problem to copy file in specific folder
that will change the name according to
host,time(%m%s) and date(%Y%M%D)
example folder name:
host_20100531.154101801
this folder name will always change...
but i just want to copy the AAA.txt and BBB.txt file..
really need... (17 Replies)
Hi all,
*I use Uwin and Cygwin emulator.
I´m trying to search for all text files in the current folder (C/Files) and its sub folders using
find -depth -name "*.txt"
The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Hello all,
I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written.
I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Hi,
I have a problem.
I have some text files in a folder. The names can be like:
emp_20080307053015.dat
emp_20080306053015.dat
emp_20080305053015.dat
emp_20080304053015.dat
The date format appended is like yyyymmdd and timestamp.
What i need is i have to copy the latest file every... (3 Replies)
Hi All,
Please advise me how to make a copy of file from a list and store in one particular location?
For example , I have aaa.txt which contains as below, But, those *usg files might be randomly store in different location....
> cat aaa.txt
adc.usg
dfdjkf.usg
ugjfk.usg
And I want... (3 Replies)