Thanks all! Very helpful solutions. On Fri, Jan 28, 2011 at 11:46 AM, Rob Ludwick <[email protected]> wrote: > One minor issue. Delineation is done by spaces, so it breaks with filenames > with spaces in the name. > > Piping everything into a while loop like this prevents that. > "ls. |head -10|while read file; do cp $file /destination/dir ; done" > > Bigger chunks of code can be surrounded with curly braces before and after > the pipe. > > Vern Ceder <[email protected]> wrote: > >>Oops, I see I have a typo in my one liner, should be: >> >>for x in `ls ./samples/*.bla | head -10`; do cp $x ; done >> >>Anyway my point is that one standard unixy way of getting the first x >>item is using head... >> >>Vern >> >>On Thu, Jan 27, 2011 at 10:54 AM, Vern Ceder <[email protected]> wrote: >>> I guess I would do it a little differently (with backticks): >>> >>> for x in `ls ./samples/*.bla | head -10`; >>> do >>> cp $x (to wherever) >>> done >>> >>> or as a one liner: >>> >>> for x in `ls ./samples/*.bla | head -10`; don cp $x ; done >>> >>> Cheers, >>> Vern >>> >>> On Thu, Jan 27, 2011 at 10:45 AM, Christer Watson >>> <[email protected]> wrote: >>>> a couple questions. don't you need to increment the $counter variable? >>>> Don't you need to use the $counter variable to choose just one item >>>> from a list of files in the /samples directory? >>>> >>>> Cheers, >>>> >>>> --Christer >>>> >>>> >>>> On Thu, Jan 27, 2011 at 10:39 AM, Travis Paul <[email protected]> wrote: >>>>> ye olden bash loops... >>>>> >>>>> #!/bin/bash >>>>> counter=0 >>>>> while [ $counter -lt 10 ]; do >>>>> cp ./samples/*.bla >>>>> done >>>>> >>>>> On Thu, Jan 27, 2011 at 10:34 AM, Jonathan Bartels >>>>> <[email protected]> wrote: >>>>>> >>>>>> I have a large batch of sample data files that are run through an >>>>>> application by copying them to an 'inbox' directory. I would like to >>>>>> do something like this: >>>>>> >>>>>> cp ./samples/*.bla --limit 10 >>>>>> >>>>>> So that only 10 of the sample files are copied instead of the whole >>>>>> mess of 10000. It can be any files. I checked the manpage and didn't >>>>>> see anything. >>>>>> >>>>>> Any ideas? >>>>>> >>>>>> -- >>>>>> ----- >>>>>> Jonathan Bartels >>>>>> >>>>>> _______________________________________________ >>>>>> Fwlug mailing list >>>>>> [email protected] >>>>>> http://fortwaynelug.org/mailman/listinfo/fwlug_fortwaynelug.org >>>>>> >>>>>> This is a public list and all posts are archived publicly. Please keep >>>>>> this in mind before posting. >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> Fwlug mailing list >>>> [email protected] >>>> http://fortwaynelug.org/mailman/listinfo/fwlug_fortwaynelug.org >>>> >>>> This is a public list and all posts are archived publicly. Please keep >>>> this in mind before posting. >>>> >>> >>> >>> >>> -- >>> Vern Ceder >>> [email protected], [email protected] >>> The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW >>> >> >> >> >>-- >>Vern Ceder >>[email protected], [email protected] >>The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW >> >>_______________________________________________ >>Fwlug mailing list >>[email protected] >>http://fortwaynelug.org/mailman/listinfo/fwlug_fortwaynelug.org >> >>This is a public list and all posts are archived publicly. Please keep this >>in mind before posting. > _______________________________________________ > Fwlug mailing list > [email protected] > http://fortwaynelug.org/mailman/listinfo/fwlug_fortwaynelug.org > > This is a public list and all posts are archived publicly. Please keep this > in mind before posting. >
-- ----- Jonathan Bartels _______________________________________________ Fwlug mailing list [email protected] http://fortwaynelug.org/mailman/listinfo/fwlug_fortwaynelug.org This is a public list and all posts are archived publicly. Please keep this in mind before posting.
