Discussion Locked

Get some information from a text file

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Our customers send us an e-mail reuqesting information about some onvoices. We write the e-mail into a text file to filter the invoice numbers. But the invoice number are mixed with the text.

I am trying to create a script file to get just the invoice nomber from the text file and put it into another text file to read it from our aplicacion. But I do not know how to do it, becaus I do no have enough experience with Unix scripts shells.

The invoice numbers is always a 10 (ten) numeric character ans it cam be mixed with special characters.

I have been trying with this command but with not good results.

grep "[0-9]" file.txt
grep "[0-9]\" file.txt
grep "[0-9]\$" file.txt
grep "[0-9]\{10\}" file.etx
etc ...

Body text from the e-mail

Mrs. XXXXXXX

Please send me information about these invoices to complete your payment next week.
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
text text text text text text text text text text
0000007022, 0024076301, 0024076301, 0699411908
text text, 0000007022, 0024076301, 0024076301, 0699411908, text text
text text text0000007022 0024076301 0024076301 0699411908text text text
and so on ......

I will really apreciate it if you can help

Thank you very much !

Best Regards

5 replies

by ghislain.levesque

#!/bin/sh
grep "[0-9]" test1|while read line
do
i=1
num_word=`echo $line|wc -w`
while [ $i -lt $num_word ]
do
inv=`echo $line|cut -d" " -f$i|cut -d"," -f1`
case "$inv" in
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]) echo $inv" is digit"
;;
*) echo $inv" is only text..."
;;
esac
i=`expr $i + 1`
done
done

in the case, you might need to change the number of occurence of [0-9] to match the number of digit in your invoice number...

Hope this help

by ghislain.levesque

Are you gone to do the same thing as last 06/25/2003 Status: Answered Points: 500
and not give points... Remember, what goes around, come around!!! last chance.
-------------------------------------------------
How can create a scrippt shell using grep to look for an specific string like year in a file contaning this information

A250865|0|0|03/06/1999|03/06/1999|G|254| |N|1|I|P|
A251999|315584|315584|29/05/2003|29/05/2003|N|2 796|2796|N|1|I|F|

I have already did it, but it find the same string in the first column, how can I separate it,

What I need is just the information in the fourth column.

For your help thank you !!

From: vavazquez65@hotmail.com Date: 06/25/2003 Status: Answered Points: 500

by vavazquez652

#!/bin/sh
grep "[0-9]" test1|while read line
do
i=1
num_word=`echo $line|wc -w`
while [ $i -lt $num_word ]
do
inv=`echo $line|cut -d" " -f$i|cut -d"," -f1`
case "$inv" in
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]) echo $inv" is digit"
;;
*) echo $inv" is only text..."
;;
esac
i=`expr $i + 1`
done
done

Thank you for your help !

I had to change this line
while [ $i -lt $num_word ]
for this one
while [ $i -lt $num_word ]||[ $i -?q $num_word ]

because I got only 2 invoices and it work

Other things is, if I have these lines
012345678901234567890123456789
or
0123456789,01234567890,01234567890
I only get the the first invoice in every line !
How an get the rest of the invoices the length is always a ten character, but it may var!

Thank you

This discussion is closed to new replies.