- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: find files from the list
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
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
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
тАО03-08-2009 11:11 PM
тАО03-08-2009 11:11 PM
find files from the list
I have a list contains values
50174214
52276142
52276142
52276498
52276869
52277263
File format:AB_20090116063203.50174214.Z
ID:50174214
Need to find files from the list which should match with ID.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-08-2009 11:32 PM
тАО03-08-2009 11:32 PM
Re: find files from the list
I think you have a data file which is having data like
AB_20090116063203.50174215.Z
AB_20090116063203.50174224.Z
AB_20090116063203.50174214.Z
AB_20090116063203.50174264.Z
AB_20090116063203.52276142.Z
AB_20090116063203.50174214.Z
now you wana to search some string as you say
then you can use below awk program
awk '{
str=substr($0,19,8)
if (str==50174214 || str==50174224 || str==50174264) print $0
}'
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-08-2009 11:47 PM
тАО03-08-2009 11:47 PM
Re: find files from the list
Yes you are right i have a data files but i extracted ID's from the data files and put it in the list.
Data files:
AB_20090116063203.50174214.Z
AB_20090116063203.52276142.Z
AB_20090116063203.52276142.Z
AB_20090116063203.52276498.Z
AB_20090116063203.52276869.Z
AB_20090116063203.52277263.Z
list(which already i have):
50174214
52276142
52276142
52276498
52276869
52277263
now i just want to find the files from another location (/A/test/) which should match the ID's in the list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-09-2009 12:20 AM
тАО03-09-2009 12:20 AM
Re: find files from the list
Then just add your input file location
awk '{
str=substr($0,19,8)
if (str==50174214 || str==50174224 || str==50174264) print $0
}'
if you wana take the output into another file then give like this at list line
}' /tmp/newdata
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-09-2009 12:42 AM
тАО03-09-2009 12:42 AM
Re: find files from the list
Can we use find command for the same task.
first we should match the data files with list ID's and display the result.
find /A/test -type f -name "AB*" -exec ls -ltr {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-09-2009 01:23 AM
тАО03-09-2009 01:23 AM
Re: find files from the list
Please check this script geetting error ./Find.sh[7]: syntax error at line 2 : `print' unexpected
#!/bin/ksh
for rf in `ls -1 /A/test/AB*`
do
str=`echo $rf|cut -d"." -f2`
echo $str
awk `{
if (str==50174214) print $rf
}`done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-09-2009 02:57 AM
тАО03-09-2009 02:57 AM
Re: find files from the list
You are using archaic ``, use $() instead. And `` instead of '':
for rf in $(ls /A/test/AB*); do
str=$(echo $rf | cut -d"." -f2)
echo $str
awk -v str="$str" -v rf="$rf" '
{
if (str == $1) print rf
}' data
done
Note this will correct the script.
You may want to use awk to build your ls command:
cd /A/test
ls -1 $(awk '
{
print "AB*" $1 ".Z"
}' /path-to/data 2> /dev/null
This may return a bunch of not found files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-09-2009 04:17 AM
тАО03-09-2009 04:17 AM
Re: find files from the list
The 'right' solution depends on what you are going to do with the matching files. Just print the names?
The right solution also depends on the 'orders-of-magnitude' of the search list versus target files list. Both small (less than 100?), One small one large?
Here is a direction for a solution in PERL. Simlar solutions can be create in a shell of course:
perl -ne 'chomp; $f{$_}++} { for (<*.Z>) { if (/\.(\d+)\.Z/) { print qq($_\n) if $f{$1}}}' list.txt
-ne # for each input line
chomp;$f{$_}++ # remove newline and add as key to an array %f
} { # close input loop and open end block
for (<*.Z>) { # look through filename glob
if (/\.(\d+)\.Z/) # looks close?
{ print qq($_\n) if $f{$1} # print if in array
}
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2009 12:18 AM
тАО03-10-2009 12:18 AM
Re: find files from the list
---------------------------------------------
#!/bin/ksh
LIST=/tmp/list.txt # List of IDs
SEARCHDIR=/tmp/dir/ # Dir to search
PREFIX=AB_??????????????.
POST=.Z
FINDCMD=""
cat $LIST | \
while read ID
do
if [ "$ID" = "" ]; then next; fi
if [ "$FINDCMD" != "" ]; then FINDCMD="$FINDCMD -o"; fi
FINDCMD="$FINDCMD -name $PREFIX$ID$POST"
done
if [ "$FINDCMD" = "" ]; then echo "list $LIST was empty"; fi
find $SEARCHDIR -type f \( $FINDCMD \)
---------------------------------------------
this will create one find for all files you are looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2009 12:21 AM
тАО03-10-2009 12:21 AM
Re: find files from the list
why noy simply:
ls -l A/test/AB*Z | grep -f your-key-file
HTH,
Rgds,
Art