- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- test for test field qualifier
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
Forums
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
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
01-09-2005 06:39 PM
01-09-2005 06:39 PM
test for test field qualifier
(1) BLF1820E-90_SemAuto_97211_9144_0310743.res
(2) BLF177C_95442_9279_0510859.res
As you can see, both fields are separated by underscore "_".
When i tried the command:
ll *_*_????_*.res
it displays the 2 files. However, when i used the command:
ll *_*_*_????_*.res
it displays only 1 file.
What i want to do is capture the 2nd last field (9144 and 9279) for both files and use it as qualifier for listing the all the files.
Maximum points for all correct answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2005 07:47 PM
01-09-2005 07:47 PM
Re: test for test field qualifier
Are all the file names of the same length.
TO capture the 2nd last field 9279
ls -l *_*_????_*.res | awk '{print $9}'| cut -c15-18
But if the filenames are of different lengths then you will have to read them from reverse order and print the digits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2005 08:18 PM
01-09-2005 08:18 PM
Re: test for test field qualifier
The file is of different length.
Can i ask how to read them from reverse order and print the digits as you suggested?
Am very new to this. Many thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2005 08:42 PM
01-09-2005 08:42 PM
Re: test for test field qualifier
me on this :-)
If you are willing to use a script that takes an
argument and prints all the file names that has
the 2nd last parameter matching the argument,
then here is your solution.
Create a file named "myls" with following contect:
----
for file in `ls *.res`
do
str=`echo $file | sed 's/_[0-9]*.res$/ /g' | sed 's/_/ /g'`
echo $str | grep -q "$1$"
if [ $? -eq 0 ]
then
echo $file
fi
done
------
To print all files with 2nd last parameter as 9144,
use:
# myls 9144
Hope this helps..
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2005 10:15 PM
01-09-2005 10:15 PM
Re: test for test field qualifier
ll *_????_[0-9]*.res
Substituting 9144 for ???? as required?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 02:29 AM
01-10-2005 02:29 AM
Re: test for test field qualifier
for x in *.res ; do
y=${x#*_}
echo ${y%_*}
done
This will display the 2nd last field of each filename
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 05:29 AM
01-10-2005 05:29 AM
Re: test for test field qualifier
> If the final field before the .res is always numeric,
> you might try
>
> ll *_????_[0-9]*.res
>
> Substituting 9144 for ???? as required?
As far as I know, this regexp will match filenames
like
*_9144_[0-9]???_????.res
9144 has to be the 2nd from last is what OP
asked for, if I understand correctly.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 12:43 PM
01-10-2005 12:43 PM
Re: test for test field qualifier
Since the file names are of different length, you can write a script where you get the number of characters (using word count)in the file name.
For Eg:- for this file
BLF1820E-90_SemAuto_97211_9144_0310743.res
ls -l *_*_*_????_*.res | awk '{print $9}'| wc -c will give 43 as the number of characters in the name. And from the reverse side if you see there are a constant number of character which is 12, to get the 2nd last number. So have the word count in a variable and substract the constant 12 to get the 2nd last field.
Indira A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2005 05:46 PM
01-10-2005 05:46 PM
Re: test for test field qualifier
1)BLF1820E-90_SemAuto_97211_9144_0310743.res
2)BLF177C_95442_9279_0510859.res
I have written a smallscript taking your two files as example.
The variable filed2 will hold the value of the second last fields (9144 and 9279) for both files and then you can use the $filed2 variable as a qualifier.
I hipe his helps
Indira A