- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script help
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
02-27-2006 04:14 PM
02-27-2006 04:14 PM
grep mbui /etc/mail/aliases| awk -F : '{print $2}'
and
cat /etc/mail/aliases |grep mbui |cut -d ":" -f2
in both case i have a output like
mina.bui@au.towerlimited.com
There is blank space in front of the mail address.
how can i eliminate this so that i got something like
mina.bui@au.towerlimited.com
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2006 04:22 PM
02-27-2006 04:22 PM
Re: Script help
You can use "sed" to remove blank space, such as
# sed '/^$/d'
or
# sed '/./!d'
Add this to your script and check ..
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2006 04:26 PM
02-27-2006 04:26 PM
Re: Script help
I am using the following lines
z=`cat /etc/mail/aliases |grep mbui |cut -d ":" -f2`
echo "User mail address is : $z"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2006 06:13 PM
02-27-2006 06:13 PM
Re: Script help
=`cat /etc/mail/aliases |grep mbui |cut -d ":" -f2 | sed ...`
By the way where is your blank space?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2006 06:55 PM
02-27-2006 06:55 PM
Re: Script help
You can use perl to this.. I got this working, just store it in a file,
# cat /etc/mail/aliases |grep mbui |cut -d ":" -f2 > test
# perl -ni.bak -e 'chop; s/^\s//; print "$_\n";' test
# cat test
should remove first blank
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2006 07:10 PM
02-27-2006 07:10 PM
Re: Script help
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 09:29 AM
02-28-2006 09:29 AM
Re: Script help
hpprod:/home/mayub/script :cat /etc/mail/aliases |grep mbui |cut -d ":" -f2 |sed '/^$/d'
mina.bui@au.towerlimited.com
hpprod:/home/mayub/script :cat /etc/mail/aliases |grep mbui |cut -d ":" -f2 |sed '/./!d'
mina.bui@au.towerlimited.com
Please suggest me the exact command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 09:57 AM
02-28-2006 09:57 AM
Re: Script help
grep "mbui" < /etc/mail/aliases | awk 'F ':' '{print $2}' | read U
echo "${U}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 10:02 AM
02-28-2006 10:02 AM
Re: Script help
>>> Where should i put that
z=`cat /etc/mail/aliases |grep mbui |cut -d ":" -f2`
echo "User mail address is : $z" <<<
In response to your above question try the following...
z=`cat /etc/mail/aliases |grep mbui |cut -d ":" -f2 | tr -d ''`
echo "User mail address is : $z"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 10:04 AM
02-28-2006 10:04 AM
Re: Script help
Nothing comes with that command
hpprod:/home/mayub/script :grep "mbui" /etc/mail/aliases | awk 'F ':' '{print $2}' | read U
> echo "${U}"
>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 10:10 AM
02-28-2006 10:10 AM
Re: Script help
Nothing happens. i got the same output. space in front of the mail address
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 10:15 AM
02-28-2006 10:15 AM
Solutiongrep "mbui" < /etc/mail/aliases | awk 'F ':' '{print $2}' | read U
echo "${U}"
should be:
grep "mbui" < /etc/mail/aliases | awk -F ':' '{print $2}' | read U
echo "${U}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 10:18 AM
02-28-2006 10:18 AM
Re: Script help
Try the awk construct below...this should certainly solve it:
# grep mbui /etc/mail/aliases | awk -F": " '{print $2}'
Note the field separator in awk is two characters ": " i.e. a colon followed by a space enclosed in double-quotes.
hope it helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 10:19 AM
02-28-2006 10:19 AM
Re: Script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 10:24 AM
02-28-2006 10:24 AM
Re: Script help
Here's an alternative to the command that you have been using...
# grep mbui /etc/mail/aliases | cut -d" " -f2
Simply replacing the field-delimiter from a colon to a space will do the trick. Goes also for the awk solution I gave you.
# grep mbui /etc/mail/aliases | awk -F" " '{print $2}'
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 10:33 AM
02-28-2006 10:33 AM
Re: Script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 10:37 AM
02-28-2006 10:37 AM
Re: Script help
Till now my aliases file is very simple but may be in future i have comma separated value. In that case what should i do to overcome that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 11:32 AM
02-28-2006 11:32 AM
Re: Script help
Continuing in Merijn's vain (using Perl) and assuming that you want to parse comma-separated aliases:
# perl -nle 'if (/mbui/) {foreach $name (map {split /,/} ((split/\s*:\s*/)[1])) {print $name}}' /etc/mail/aliases
This would take entries like:
operator : root,khashru,whomever
...and output:
root
khashru
whomever
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2006 11:42 AM
02-28-2006 11:42 AM
Re: Script help
I'm sorry, I changed the example as I wrote it. If you wanted to match "oper" as in "operator" in the aliases file:
# perl -nle 'if (/oper/) {foreach $name (map {split /,/} ((split/\s*:\s*/)[1])) {print $name}}' /etc/mail/aliases
This would take entries like:
operator : root,khashru,whomever
...and output:
root
khashru
whomever
Thus, simply change the token you want to match as needed.
Regards!
...JRF...