Operating System - Linux
1754229 Members
3467 Online
108812 Solutions
New Discussion юеВ

need help on getting data in a file

 
SOLVED
Go to solution
Patrice Blanchard_2
Frequent Advisor

need help on getting data in a file

Hi,

i have this script:

user=`whoami`
elist=`whoami`@mydomain.com
date_str=`date "+%m/%d/%y%H%M%S"`
subject="PDF file"
set -x
cat "$1" |tr -d `echo "\015"` > "$1""pdf"
echo "$2" "$1" "$3"
/baan4/c4/bse/starjet/starpage -s"$3" -c"$2" -d/tmp/$user.pdf -m:pdf "$1""pdf"
uuencode /tmp/$user.pdf $user$date_str.pdf | mailx -m -s "$subject" $elist

where user will get by email a pdf file named with this format mylogindatetime.pdf

script is working ok but here is the catch. I need to fetch invoice number stored in "$1""pdf" and use it has a the name of the file instead of the login date and time.

if i do a "grep Invoice" of the file i get:
"customer name Invoice N: 12345 SLS"

how can i fetch the 12345 SLS and put it in a variable so i can use it in the script?

I'm no expert on scripting so any help will be appreciated.

Regards

PB
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: need help on getting data in a file

Hi:

The use of a simple 'cut' will extract the fields you want:

# X="customer name Invoice N: 12345 SLS"
# Y=`echo ${X}|cut -d" " -f 5-6`
# echo ${Y}
12345 SLS

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: need help on getting data in a file

Hi:

This is clearer, perhaps:

# VAR=`grep "Invoice" file|cut -d " " -f 5-6`

Regards!

...JRF...
Peter Nikitka
Honored Contributor
Solution

Re: need help on getting data in a file

Hi,

if the requested items are the last part of this line:

awk '/ Invoice / {print ($(NF-1),$NF);exit}' "$1"pdf | read num str

and use $num and $str for these values.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Patrice Blanchard_2
Frequent Advisor

Re: need help on getting data in a file

Hi,

thanks for your help on this. Both info were good.

Regards

PB
Arturo Galbiati
Esteemed Contributor

Re: need help on getting data in a file

Hi,
grep Invoice f3|tr -d '"'|cut -d" " -f5,6|read x y

It runs on my HPUx11i:
/tmp/>cat f3
"customer name Invoice N: 12345 SLS"
/tmp/>grep Invoice f3|tr -d '"'|cut -d" " -f5,6|read x y
/tmp/>echo $x
12345
/tmp/>echo $y
SLS

HTH,
Art