- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- While Read a 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
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
тАО11-28-2007 06:27 AM
тАО11-28-2007 06:27 AM
cat email_list | while read L
do
mailx -s "Test Data" $L < /dev/null
done
The email_list is a file with various email address, one line per email address. Let's say I have 10 entries and I want to comment out one line with an "#". Now when my script runs, I want to send an email out to 9 people instead of 10. I want to comment out the address rather than delete it. How can I set up my "while read" instruction to bypass any lines with an "#" in it?
Solved! Go to Solution.
- Tags:
- grep
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2007 06:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2007 07:00 AM
тАО11-28-2007 07:00 AM
Re: While Read a File
Pete, it worked like a charm. Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2007 07:01 AM
тАО11-28-2007 07:01 AM
Re: While Read a File
One simple way:
# cat ./mailer
#!/usr/bin/sh
while read X L
do
[ ${X} = "#" ] && continue
mailx -s "Test Data" ${L} < /dev/null
done < email_list
If your file has a "#" field as the first field of the line it will be skipped.
Notice, too that your can eliminate the 'cat' process. The loop reads your file directly.
Regards!
...JRF...
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-28-2007 09:36 AM
тАО11-28-2007 09:36 AM
Re: While Read a File
Pete, you know the # should be at the begining of the line and therefore your grep should be anchored to the begining of the line: grep -v "^\#"
and James, your solutions assumes there is always a space after the #, as in:
# thisworks
#thisdoesn't
and you improve performance by eliminating the cat, but still run mailx for each address
something like this would be better,
comments can be at the end of the line,
as in:
addr # to me
will work and it creates a variable of the addresses and runs mailx just once
addrs=""
while read myAddr
do
myAddr=${myAddr%%#.*} #remove first # and everything on the line after it
myAddr=${myAddr%%#} #remove # if it is last character on the line or only character
addrs="${addrs} ${myAddr}"
done < email_list
mailx -s sub $addrs