Re: list the file need for syntax (175 Views)
Reply
Super Advisor
rajesh73
Posts: 448
Registered: ‎03-17-2009
Message 1 of 4 (197 Views)

list the file need for syntex

[ Edited ]

i want to list the file from 1_11_data01.dbf to 1_78_data01.dbf

and i need to copy the same file to some other location. please advise the command

 

1.list command

2.copy command

 

example file name

 

1_10_data01.dbf

1_11_data01.dbf

1_12_data01.dbf

1_13_data01.dbf

1_14_data01.dbf

1_15_data01.dbf

1_16_data01.dbf

1_17_data01.dbf

1_18_data01.dbf

1_20_data01.dbf

.

.

.

1_300_data01.dbf

 

Honored Contributor
Laurent Menase
Posts: 1,079
Registered: ‎11-06-2003
Message 2 of 4 (194 Views)

Re: list the file need for syntex

if they are not in the same directory.

 

find $pathwherethefilesare -name 1_\*_data01.dbf -exec cp {} targetdir \;

 

 

or:

find $pathwherethefilesare -name 1_\*_data01.dbf >/tmp/listfile

 

cp $(cat /tmp/listfile) targetdir

 

or many other

Honored Contributor
Patrick Wallek
Posts: 13,786
Registered: ‎06-21-2000
Message 3 of 4 (185 Views)

Re: list the file need for syntex

If you want to list that specific range of file, you can do something like:

 

ls 1_[1-7][0-9]_data01.dbf

 

This will give you all files in the range 1_10_data01.dbf through 1_79_data01.dbf.

 

You can use the same syntax with the brackets in a 'cp' command.

Acclaimed Contributor
Dennis Handly
Posts: 25,277
Registered: ‎03-06-2006
Message 4 of 4 (175 Views)

Re: list the file need for syntax

>I want to list the file from 1_11_data01.dbf to 1_78_data01.dbf

 

If you only want these and not the edges given by Patrick's regex slice, then you need a script.  Or use grep to remove the 3 files that you don't want.

 

list_data_files.sh:

#!/usr/bin/ksh

# Lists files from 1_11_data01.dbf to 1_78_data01.dbf

 

(( index = 11 ))

while (( index <= 78 )); do

   if [ -f 1_${index}_data01.dbf ]; then  # check if there

      echo "1_${index}_data01.dbf \c"

   fi

   (( index += 1 ))

done

 

Then to list or cp you can use:

ls $(list_data_files.sh)

cp $(list_data_files.sh) targetdir

 

>cp $(cat /tmp/listfile) targetdir

 

So close, you left an evil cat there.  ;-)

cp $(< /tmp/listfile) targetdir

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.