I need to routinely cp a file out of the highest incremented folder named PROD_2_6.1_xxx where xxx (3 numerical values) is incremented only once a night starting at 100 and ending 999 over a period of time. I am not worried about copying a subset of a complete file while it is being created by some other process.
example:
I have only the most rudimentary understanding of how to copy and no practical experience despite searching for an answer. All I have managed to pull together is:
Any help is appreciated :b Thanks everyone!
Last edited by sf_cb; 01-15-2015 at 04:37 PM..
Reason: added code tags - first time poster.
In addition to showing us what you have tried (as requested by RudiC), please also give us more information about your directory names. Is x in PROD_2_6.1_x always three digits? What range of x values does your script need to be able to process?
What do you mean by the "latest file" in a directory? (Modified most recently? Last filename in an alphabetic list of filenames? Something else?) How do you know you won't be copying a subset of a complete file while it is being created by some other process?
This User Gave Thanks to Don Cragun For This Post:
The command:
will give you a list of the directories you're interested in in increasing alphabetic order. Since all of the numbers at the end of these directory names contain 3 digits, this will also be in increasing numeric order. Adding the -r option to ls will give you the list in reverse order. Piping the output of ls through the command: head -n 1 will give you just the first line, which will be the directory that you want. You can use save that directory name in a variable using command substitution and variable assignment:
To copy a file named filename.txt from that directory to another directory (in this example, named /target/directory), you can then use:
You can change the name of the file in the target directory using the first form above; the second form will copy the source file to the target directory using the same name as the final component of the source file pathname as the filename of the copy in the target directory.
Hi,
I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content.
for example... (3 Replies)
Hi Guru's,
I am new to unix scripting. I have a huge file with user details in it(file2) and I have another file with a list of users(file1). Script has to search a user from file1 and get all the associated lines from file2.
Example:
fiel1:
cn=abc
cn=DEF
cn=xyx
File 2:
dn:... (10 Replies)
Hi
I'm trying to look through a series of directories in A folder, lets just call it A:
for example:
A/1
A/2
A/3
Etc and I wish to move the files in the folder if they are bigger than a certain size into a structure like below:
A/TooBig/1
A/TooSmall/1
A/TooBig/2
A/TooSmall/2... (1 Reply)
I have a file named file.txt that looks as follows
//class1.txt
45
234
67
89
90
//class2.txt
456
34
78
89
120
class1 and class2.txt are the names of files in a folder named folder1.
The content of class1.txt file in folder1
67 9
89 5
234 9The content of class2.txt file in... (1 Reply)
I have a file myfile with only one value 1000.I am using it in a shell script.Each time i run the script,the file shud get incremented by 1. I have used the below code for incrementing the value-
curr=`cat myfile`
echo $curr
curr=`expr $curr + 1`
But i am not sure how to save this replaced... (2 Replies)
Hi everyone.
I'm in need of a solution where i need to rename a folder to a name that's inside an XML file in that folder.
OS is Ubuntu 9.10 with Gnome.
I've tried using grep, sed and xpath, but can't seem to find a solution.
This is the simplified folder structure:
FOLDER-NAME
-... (4 Replies)
Hello all, this is my first post while i am trying to understand unix.
I would basically like to know if i can do this:
Lets say i have a folderA and folderB
And i save something in folderA
Can i make a script that checks folderA latest file, then compares it with the date of latest file in... (16 Replies)
Hi all,
I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt.
I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Hi
I a really need help.
I got simply shell script which store result into the specific file
in this case xxx_001.txt
And after another run script I would like to create the same file but
value 001 is incremented by 1 -> xxx_002.txt a so on.
If I gonna use awk utility then result... (4 Replies)