Page 1 of 1

Shell Scripting: Piping part of ls output

Posted: Thu Oct 26, 2006 12:30 pm
by nigma
I've got a bunch of files in the form:
Apple (2006-04-11)
Berry (2006-01-13)

I'd like to run ls on the directory containing these files and then pipe only the date portion (YYYY-MM-DD) of the filenames into another file.

Can anyone point me the right direction?

Posted: Thu Oct 26, 2006 1:24 pm
by Weirdan
untested

Code: Select all

ls | sed "s/.*(//g" | sed "s/)//g" > file.list

Posted: Thu Oct 26, 2006 1:26 pm
by Weirdan
or

Code: Select all

ls | sed "s/[^0-9-]//g" > file.list

Posted: Thu Oct 26, 2006 1:42 pm
by volka
or

Code: Select all

ls | cut -d " " -f 2
cut -d " " -f 2 : display second field of a space-sparated list.
see http://www.gnu.org/software/coreutils/m ... ils_8.html

Posted: Thu Oct 26, 2006 5:23 pm
by Chris Corbyn
volka wrote:or

Code: Select all

ls | cut -d " " -f 2
cut -d " " -f 2 : display second field of a space-sparated list.
see http://www.gnu.org/software/coreutils/m ... ils_8.html
Heh, cool, how come I've never seen cut used before? :( I should do more bash scripting :)