- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: for loop + shell scripting
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
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
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
тАО04-16-2007 05:47 PM
тАО04-16-2007 05:47 PM
for loop + shell scripting
Issue is i have a list of files and have to delete all files one by one but i am not able to use for loop. Actually there is one directory where some files like a1, a2 a3 will be there and we have to move files on the basis of lowest seqence file first. So let me know how we can do this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2007 05:58 PM
тАО04-16-2007 05:58 PM
Re: for loop + shell scripting
How about a while loop
ls -1 > list
filetonotdelete=nodelete.dat
while read -r filename
do
if [ "$filename" != "$filetonotdelete" ]
then
echo "Not deleting $filetonotdelete"
else
echo "Deleting $filename"
rm -f $filename
fi
done < list
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2007 06:20 PM
тАО04-16-2007 06:20 PM
Re: for loop + shell scripting
Give details of file sequence & Some examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2007 06:39 PM
тАО04-16-2007 06:39 PM
Re: for loop + shell scripting
want to keep "a3", you might use something
like this:
$ cat pur.sh
#!/bin/sh
ls -1 $1 | \
(
read c
while [ -n "$c" ] ; do
p="$c"
read c
if [ -n "$c" ] ; then
rm "$p"
fi
done
)
./pur.sh "a*"
But that would break when you got up to
"a10".
Until you can say exactly what you would like
to do, there is not much hope of figuring out
how to do it. After that, it's a lot like
writing a computer program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2007 09:23 PM
тАО04-16-2007 09:23 PM
Re: for loop + shell scripting
If you know what files you want to save, remove them from your list. Then to remove the rest with:
$ rm -f $( < list-of-files )
(This assumes they fit within the shell's command line.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2007 09:35 PM
тАО04-16-2007 09:35 PM
Re: for loop + shell scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-16-2007 09:36 PM
тАО04-16-2007 09:36 PM