- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- cut, grep etc....
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
12-16-2002 11:21 AM
12-16-2002 11:21 AM
I'm really fu*ked up with grep an cut commands. And I'm trying to do a script in which I need to use them...
Here is the structure of the content of the file that I'm trying to read:
*********** START ***********
theemails@areonthatline.com
The subject is on that line
Multiple line of data
Multiple line of data
Multiple line of data
Multiple line of data
Multiple line of data
************ END ************
What I need to do, is to send mail a the emails that are listed on the "real first" line and that subject on the other line. And then the rest of the file I'm gonna put it in the body of the email. What I wanna you guys tell me is how can I extract the emails line, the subject line and the rest of my text file. I just need to put the extraction in variables with them after I'm gonna use my script to send mail with a body... Please just told me how can I use grep or cut to get the info I need!!!
Regards!
Jonathan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2002 11:27 AM
12-16-2002 11:27 AM
Re: cut, grep etc....
however, if grep and cut hav you throughly confused, sed and awk will make your head spin as they are cryptic, but powerful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2002 11:36 AM
12-16-2002 11:36 AM
SolutionFor your problem, it looks like you have a fixed format at least at the top of your data, which is good.
4th line is subject
3rd line is the email addresses
Lets call your file INFILE. Subject is the easiest to extract, so here it is...
#!/bin/sh
SUBJECT=`head -4 $INFILE|tail -1`
Getting the email addresses will require a loop. We can use head and tail to pull the 3rd line from the file to make a loop. A blank space will be treated as a separator.
for ADDRESS in `head -3 $INFILE|tail -1` ; do
mailx $ADDRESS -s $SUBJECT $INFILE
done
Assuming that you want the whole INFILE mailed, the above will work just fine. If you dont want the subject and addresses from the file mailed, you will have to be a bit more creative with the script.
If this is the case, I'd recommend making a temp file with the data you do want to mail, then wc to count lines, expr to remove calculate lines -4(remove header), then tail to build your temp file.
Hope it helps, and no vast knowledge of grep or cut required for this job.
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2002 11:41 AM
12-16-2002 11:41 AM
Re: cut, grep etc....
Well said Shannon
Jonathan please take notice.
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2002 11:44 AM
12-16-2002 11:44 AM
Re: cut, grep etc....
Sorry for the "F" word.... I'll watch it in the future!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2002 01:27 PM
12-16-2002 01:27 PM
Re: cut, grep etc....
Where /tmp/ooo is your INPUT file:
#!/usr/bin/ksh
cd /tmp
rm abcd*
csplit -s -f abcd -n 4 /tmp/ooo '/^\*\*\*\*\*\*\*\*\*\*\*\* END \*\*\*\*\*\*\*\*
\*\*\*\*$/+1' {*}
for i in `ls abcd*`
do
crazy=""
auth=""
subj=""
ema1=""
ema2=""
crazy=`cat $i | head -5 | tail -2`
auth=`echo $crazy|cut -d" " -f1`
subj=`echo $crazy|cut -d" " -f2-`
ema1=`echo $auth|cut -s -d"@" -f1`
ema2=`echo $auth|cut -s -d"@" -f2`
if [ "$ema1" -a "$ema2" ]; then
echo "Thank you for replying" | mailx -s "re: \"${subj}\"" $auth
echo "--------------------------"
fi
done
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2002 06:26 AM
12-17-2002 06:26 AM
Re: cut, grep etc....
You have some good replies already but I still wanted to put in my two cents. If I am understanding this correctly all you need is 'sed'. The 'sed' command will print any number of lines in a file.
If you have a number of files to parse through then using a loop would be good. So try this:
#!/bin/ksh
for infile in
do
inaddr="`sed -n '3p' ${infile}`"
insubj="`sed -n '4p' ${infile}
sed -n '6,$p' ${infile} | mailx -x${insubj} ${inaddr}
done
exit 0
I was not sure on the exact line numbers so just change the 3, 4, and 6 to whatever you need them to be.
Hope this helps
Thomas