using gsed with cp to sort files in directory - every N file copy to new place
Hi all,
I'm having a problem with some basic piping issues...
I have been able to get in a directory and ls | gsed in order to list every N file for instance:
The thing is I want to be able to copy the output files to a new directory. Basically directory /all has a bunch of jpegs in there. I need to copy every third one, starting at #2 to /selects.
Can some kind person point me on the way with this. I am on OS X but installing gsed as the OS X sed seems inconsistent with the examples I am using to get the initial output...
THANK YOU
Last edited by radoulov; 10-12-2011 at 04:20 PM..
Reason: Code tags!
OSX's default sed is an ancient BSD incarnation which doesn't even support things like \n. gsed is a good idea.
I don't know how "2~5p" is supposed to work though, trying it on /etc/passwd I actually get more lines out of it than I put in!
How about
One of the simplest ways to use awk is an expression which tells it whether to print the current line or not. NR is the number of records. So it will print the current line only when the line number divided by 3 has a remainder of 0 -- so line 3, 6, 9, 12, ...
Then you feed it into a while loop and move files one by one.
If you wanted to avoid running cp 30,000 times, you could pipe them into xargs/tar:
running 'tar -cf - file1 file2 file3' bundles files into a tape archive printed directly to standard output. xargs converts file names in a pipeline into arguments fed into tar. Piping that directly into tar -xf extracts the files. -C tells it where. So it pipes the contents of all the files between the two tars and creates them where you want.
Just beware that if there are too many files, tar will get run more than once, causing the pipe to break early, so some may not be copied. My first example is technically safer, if less efficient.
ok, good to know. this was an input of about 750 files, outputting 250 and from what I can tell at first glance seems to have worked well. I'll keep an eye on it. Thank you again for the help and lesson.
Hi All,
Daily I am getting the updated file.
I have to search for this file in all directories and sub directories.
If the file existed in a particular directory then move this updated file to that particular directory.
If the file is not existed in any of the directories then place this... (4 Replies)
Hi Guys,
I want to search for a specific file in a directory which have a "b" letter as the 3rd character in the name of the file.
For Example :
/abc/efg/ldbjfblkj.sh
/abc/efg/erublkd.sh
/abc/efg/eibueora.sh
/abc/efg/kfvnmnb.sh
Since we have 2 files with "b" as a 3rd character in... (5 Replies)
How to copy files from one directory to another directory with the subfolders copied.
If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*.
I do not want to create sub folders in folder2.
Can copy command create them automatically?
I tried cp -a and cp -R but did... (4 Replies)
I am trying to write a script that will copy all file listed in a text file (100s of file names) to a new directory
Assume script will run with main as current working directory and I know how many files/lines will be in List.txt
Im trying to work up a test script using this model
Contents of... (2 Replies)
I have a NAS and I upload my videos to it from time to time. the video format is 3gp but my media player PBO could only play avi. I want to copy these files to different directory and change the extention from 3gp to avi. (yes I want to keep the original version and create a duplicate version with... (0 Replies)
Hello all.
I'm not getting the hang of Paths. I have a dir w/files that I want to copy to another dir. Right now I am in the "source" directory. I want to copy it to Ch7.
"cp -r source Ch7". Ch7 was already created.
1st msg.: cannot stat `source`: No such file or dir.
I typed pwd & got... (3 Replies)
Dear Gurus,
I need you to advice or suggestion about the best solution to copy data around 200-300G from serverA(location A) to serverB(location B). Normally, I will share folder and then copy but it takes too long time(about 2 days).
Do you have any suggestion or which way should be... (9 Replies)
hello
i have a requirement where i have a direcotry in which i get files in the format
STOCKS.20080114.dat
STOCKS.20080115.dat
STOCKS.20080117.dat
STOCKS.20080118.dat
i need to loop through the directory and sort by create date descending order and i need to process the first file.
... (1 Reply)