- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: show files in a numeric range
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2011 01:19 AM
10-12-2011 01:19 AM
In directories I have hundreds of files like:
file0001.lst
file0002.lst
.
.
file0999.lst
i want to show files in a index range, example 30 til 60 .
input : index1
input : index2
my idea:
index1=$1
index2=$2
for file in $( ls file* )
do
index=$( basename ${file} .lst |sed "s|[a-z]||g" )
if [ ${index} -ge ${index1} -a ${index} -le ${index2} ]
then
ls -al $file
fi
done
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2011 03:50 AM - edited 10-12-2011 03:53 AM
10-12-2011 03:50 AM - edited 10-12-2011 03:53 AM
Re: show files in a numeric range
If your format is always: file####.lst:
#!/usr/bin/ksh
# List files by range
if [ $# -ne 2 ]; then
echo "Usage: $0 first last" 1>&2
exit 1
fi
typeset -i first=$1 second=$2
typeset -Z4 subnum
ls $(
while (( first <= second )); do
subnum=$first
echo "file$subnum.lst"
(( first += 1 ))
done) 2> /dev/null # ignore missing files
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2011 03:52 AM
10-12-2011 03:52 AM
Re: show files in a numeric range
Hi:
One way:
# perl -nle '($n)=m{\D+(\d+)};print if $n>=30 && $n<=60' file
...prints the names matching the criteria.
# perl -nle '($n)=m{\D+(\d+)};system(qq(ls -l $_)) if $n>=30 && $n<=60' file
...runs 'ls -l' on the matches.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2011 05:20 AM
10-12-2011 05:20 AM
Re: show files in a numeric range
hello,
both answers are perfect, shell i understand , perl it isn't so easy, but i can extend to use shell variables
perl -nle '($n)=m{\D+(\d+)};print if $n>=30 && $n<=60' file
my version for using in a shell, hope right ?
ls file* | \ first=98 second=105 perl -nle '($n)=m{\D+(\d+)};print if $n>=$ENV{"first"} && $n<=$ENV{"second"}'
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2011 05:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2011 05:38 AM
10-14-2011 05:38 AM
Re: show files in a numeric range
hello,
last question : when i try:
ls /tmp/20111010/file/file* | \
first=95 second=105 perl -nle '($n)=m{\D+(\d+)};print if $n>=$ENV{first} && $n<=$ENV{second}'
it shows nothing , print $n shows 20111010 .
ls /tmp/file/file* | \
first=95 second=105 perl -nle '($n)=m{\D+(\d+)};print if $n>=$ENV{first} && $n<=$ENV{second}'
is ok
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2011 06:03 AM - edited 10-14-2011 01:54 PM
10-14-2011 06:03 AM - edited 10-14-2011 01:54 PM
Re: show files in a numeric range
>when I try: ls /tmp/20111010/file/file* | \
>it shows nothing, print $n shows 20111010 .
Most likely it takes the first string of digits in your directory path and not the last in your filename?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2011 06:07 AM - edited 10-14-2011 06:23 AM
10-14-2011 06:07 AM - edited 10-14-2011 06:23 AM
Re: show files in a numeric range
@support_billa wrote:
last question : when i try:
ls /tmp/20111010/file/file* | \
first=95 second=105 perl -nle '($n)=m{\D+(\d+)};print if $n>=$ENV{first} && $n<=$ENV{second}'
it shows nothing , print $n shows 20111010 .
Hi:
What's different about '/tmp/file/file' versus ' /tmp/20111010/file/file' ?
That is, show us what your 'ls' of each returns.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2011 08:34 AM
10-16-2011 08:34 AM
Re: show files in a numeric range
The number test should be done on the file name only if I read this thread correctly, not on the directory name. I'd use File::Find;
$ perl -MFile::Find -wle'find(sub{/(\d+)/&&$1>=95&&$1<=105&&print},"/tmp/20111010/file")'
but you might find that too terse