- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: read data in 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
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
11-23-2005 04:00 AM
11-23-2005 04:00 AM
what's the command to read the data in a file? I have a file and if a do the command:
grep Customer file
it returns:
file:Customer : 269852
How can i read the 269852 ?
Regards
PB
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2005 04:03 AM
11-23-2005 04:03 AM
Re: read data in a file
while read -r dataline
do
echo $dataline
# perhaps awk -F: '{print $2}'
# for further procesing
done < filename
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
11-23-2005 04:06 AM
11-23-2005 04:06 AM
Re: read data in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2005 04:14 AM
11-23-2005 04:14 AM
Re: read data in a file
i want to be able to catch the customer number in a file generated by my ERP system so that i could send an email by mailx.
So the process woulb by:
fetch the customer number in a file then read another file with that customer number to get the email address so i can send an email by mailx.
file1 would have Customer : 268852
file2 would have 268852 email@somewhere.com
then i could do a mailx to email@somewhere.com
is it feasible?
Regards
PB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2005 04:22 AM
11-23-2005 04:22 AM
Re: read data in a file
Very similar questions for line 2: Does it contain only one customer number?
It would be very helpful if you listed a dataset of file1 and file2 -- unless you already have and these are simply one line files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2005 04:45 AM
11-23-2005 04:45 AM
Re: read data in a file
file1 is an invoice for 1 customer so you'll have multiple lines in file1 but only 1 line with Customer : xxxxxx so you'll have something like:
invoice
blablabla
customer: 258965
blablabla
line 1 item price
...
file2 would have multiple customer number, 1 per line so you'll have something like this:
268852 email1
245896 email2
256974 email3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2005 05:02 AM
11-23-2005 05:02 AM
Solutioncust=`awk '/^customer:/{print $2}'`
if [[ "x$cust" = "x" ]] ; then echo "no customer line..." ; exit ; fi
email=`awk '/^${cust}/{print $2}'`
if [[ "x$email" = "x" ]] ; then echo "no email for $cust" ; exit ; fi
mailx -s "subj" $email
Note I added code to exit if it can't find the data in the file
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2005 05:37 AM
11-23-2005 05:37 AM
Re: read data in a file
--------------------------------------
#!/usr/bin/sh
typeset PROG=${0##*/}
if [[ ${#} -lt 2 ]]
then
echo "${PROG}: requires 2 arguments" >&2
exit 250
fi
typeset FILE1=${1}
typeset FILE2=${2}
shift 2
if [[ ! -r ${FILE1} || ! -f ${FILE1} ]]
then
echo "${PROG}: Can't open ${FILE1}" >&2
exit 248
fi
if [[ ! -r ${FILE2} || ! -f ${FILE2} ]]
then
echo "${PROG}: Can't open ${FILE2}" >&2
exit 246
fi
typeset -i STAT=255
typeset CNUM=$(awk -F ':' '/Customer/{print $NF; exit(0)}' ${FILE1})
if [[ -n "${CNUM}" ]]
then
STAT=254
typeset A=$(echo "{ if (\$1 == target) {print \$0; exit(0)}}")
typeset ADDRESS=""
typeset DUMMY=""
awk -v "target=${CNUM}" "${A}" ${FILE2} | read DUMMY ADDRESS
if [[ -n "${ADDRESS}" ]]
then
echo "Cnum: ${CNUM}"
echo "Address: ${ADDRESS}"
STAT=0
fi
fi
exit ${STAT}
--------------------------------------
At the point where I am echo'ing ${CNUM} and ${ADDRESS} is where you should build your mailx command.
Invoke the script like this:
myscript.sh /xxx/yyy/file1 /zzz/ttt/file2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2005 06:02 AM
11-23-2005 06:02 AM
Re: read data in a file
You probably have a bunch of invoice files no?
So you may want to consider to read the email files once and just remember all the number to email combo's
Then loop through the input files.
Working perl example below.
hth,
Hein.
---- invoice_email.pl ------------
$email = shift @ARGV or die "Please provide number-email file";
$invoices = shift @ARGV or die "Please provide invoice file specs";
open X, "<$email" or die "Could not open number-email file $email";
while (
chomp;
($number, $address) = split;
$addresses{$number} = $address;
}
foreach (glob $invoices) {
open X, "<$_" or die "Could not open invoice file $_";
while (
if (/customer:\s+(\d+)/) {
$number = $1;
$address = $addresses{$number};
if ($address) {
print "system ( mailx -s $number $address ... goes here\n)";
} else {
print "No Email address found for customer: $number\n";
}
}
}
}
------- sample run ------
/tmp]$ perl x.p email "invo*"
No Email address found for customer: 258965
system ( mailx -s 268852 email1 ... goes here)
system ( mailx -s 245896 email2 ... goes here)
-------- input date -----
# grep "cust" invo*
invoice1:customer: 258965
invoice2:customer: 268852
invoice3:customer: 245896
# cat email
268852 email1
245896 email2
256974 email3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2005 08:41 PM
11-23-2005 08:41 PM
Re: read data in a file
Get Customer number from file and grep that in file2 and get the mail Id and send invoice?
Then,
# cat file1
invoice
blablabla
customer: 258965
blablabla
line 1 item price
...
# cat file2
268852 email1
245896 email2
256974 email3
258965 email@somewhere.com
# awk '/[Cc]ustomer:/ { print $2 }' file1 | xargs -i grep {} file2 | awk '{ print $2 }'
email@somewhere.com
# mailx -s "subject" $(awk '/[Cc]ustomer:/ { print $2 }' file1 | xargs -i grep {} file2 | awk '{ print $2 }') < messagefile
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2005 06:25 AM
11-28-2005 06:25 AM
Re: read data in a file
PB