- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: parse out last bit of file name in scripts
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-09-2004 03:41 AM
02-09-2004 03:41 AM
for i in `cat /tmp/file`
do
yada
send output to file.
done
The /tmp/file contains...
pass.change.some_server1
pass.change.some_server2
pass.change.some_server3
pass.change.some_server4
I am trying to add mailing of the output file, but would like to add to the subject line the end part of the pass.change.some_server1.
so just some_server1.
I thought I could do it with an awk script but I have not been able to get it to work.
I want to take $i and parse it down to the last part of some_server1 and store that is a variable then use it in the subject line.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 03:47 AM
02-09-2004 03:47 AM
SolutionI would do something like this (if I understood your requirement correctly)
//
EMAIL=your_id@your_domain.com
for FILE in $(cat /tmp/file)
do
SERVER=$(echo $FILE|awk '{FS=".";print $3}')
mailx -s "Something on $SERVER" $EMAIL < $FILE
done
//
SERVER=$(echo $FILE|awk '{FS=".";print $3}')
Is the key.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 03:50 AM
02-09-2004 03:50 AM
Re: parse out last bit of file name in scripts
do
XX=$(echo "${i}" | awk -F '.' '{print $NF}')
echo "XX = ${XX}"
done
The trick is to define '.' as awk's field separator and then print the last field ($NF) on each line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 03:57 AM
02-09-2004 03:57 AM
Re: parse out last bit of file name in scripts
server="pass.change.some_server3"
file=${server##*.}
print $file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 04:02 AM
02-09-2004 04:02 AM
Re: parse out last bit of file name in scripts
you could also extract it with
expr "$LINE" : ".*\(some_server.*\).*"
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 04:05 AM
02-09-2004 04:05 AM
Re: parse out last bit of file name in scripts
for fln in $(cat /tmp/file)
do
server=$(echo $fln | cut -f3 -d".")
send output to file.
done
Regards,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 04:19 AM
02-09-2004 04:19 AM
Re: parse out last bit of file name in scripts
do
server=$( print $i | sed -e 's/^.*\.//' )
print $server
done
Should give you:
some_server1
some_server2
some_server3
some_server4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 05:14 AM
02-09-2004 05:14 AM
Re: parse out last bit of file name in scripts
so my effort is this
mailx -s `awk -F"." '{ print $3;exit }' /tmp/file' someone@some.domain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 05:15 AM
02-09-2004 05:15 AM
Re: parse out last bit of file name in scripts
mailx -s `awk -F"." '{ print $3;exit }' /tmp/file` someone@some.domain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 07:32 AM
02-09-2004 07:32 AM
Re: parse out last bit of file name in scripts
set -u
PATH=/usr/bin
MYEMAIL=somebody@someplace.com
cat /tmp/file | read MYFILE
do
SERVER=${MYFILE##*.}
mailx -s "$SERVER output file" < $MYEMAIL
done
The funny incantation ##*. says to return anything following the last appearance of the . character. For this construct, any number of dots may appear and only the text following the last dot will be returned. This is similar to ${some_full_pathname##*/} which returns just the name at the end of a bunch of slashes, like the basename command.
Bill Hassell, sysadmin