- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- list file
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
06-05-2008 05:47 PM
06-05-2008 05:47 PM
do
xxx
done
I have the above script to list all *.txt in /tmp then do xxx , if I want to list all *.txt but exclude aaa.txt , can advise what can i do ?
thx
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2008 06:01 PM
06-05-2008 06:01 PM
Re: list file
for file in $(ls /tmp/*.txt | grep -v aaa.txt)
do
xxx
done
NOTE -- Notice I used $() around the command rather than that back-ticks (backwards apostrophe, whatever..) symbols. This makes for easier reading and provides that EXACT same functionality.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2008 06:17 PM
06-05-2008 06:17 PM
SolutionI'm sure that the 'aaa' is just an example.
The 'best' solution depends on how complex that 'aaa' really is. Is it just one piece of string?
Example of the method 1:
for file in `ls *.tmp | grep -v aaa`
do
echo --- $file ---
done
Example for method 2:
for file in $(ls *.tmp)
do
if [[ $file != aaa.tmp ]] ; then echo --- $file --- ; fi
done
Example of a perl solution:
$ perl -e 'foreach (<*.tmp>) { next if /aaa/; print qq(--- $_ ---\n)}'
Same presented as 'program' vs one-liner above:
foreach (<*.tmp>) {
next if /aaa/;
print qq(--- $_ ---\n);
}
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2008 06:17 PM
06-05-2008 06:17 PM
Re: list file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2008 02:46 AM
06-06-2008 02:46 AM
Re: list file
there are extended filename pattern in ksh, which should be available in HP's Posix shell as well - look at my examples:
ef3nip00@forth ls *.txt
aaa.txt aaab.txt comp_list.txt serial.txt
# Just skip aaa.txt
ef3nip00@forth ls !(aaa).txt
aaab.txt comp_list.txt serial.txt
# skip aaa*.txt
ef3nip00@forth ls !(aaa*).txt
comp_list.txt serial.txt
So for your code:
for file in !(aaa).txt
do print action $file
done
A more general solution would be an analyze of the name in the loop itself:
for file in *.txt
do
case $file in
aaa.txt) continue;;
...
esac
print action $file
done
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2008 12:15 AM
06-07-2008 12:15 AM
Re: list file
ls /tmp/!(aaa.)txt|xargs -i xxx {} {}.bak
Below xxx(your action is replaced by the copy command - hence all the txt files except aaa.txt will be copied with an extension of .bak)
ls /tmp/!(aaa.)txt|xargs -i cp {} {}.bak
Is not time, to start assigning points. Your profile shows you have not started assigning points.
Rgds.