To make sure I don't violate rule #7


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To make sure I don't violate rule #7
# 1  
Old 08-19-2008
To make sure I don't violate rule #7

I am hoping to find out if it is possible to use some sort of UNIX programming/scripting tools to solve a problem I have with reformatting email messages that are sent out of my IBM UNIX (AIX) system. I'm thinking some advanced awk/sed may work

I do not have the time or the ability to do this work, if it's even possible. So if it is possible, I would be looking for someone to do the work for me.

I want to make sure I stay within the rules, so can you pleae advise the correct way to ask this in the forums or which forums I should use.

Thanks.

Todd Smilie
# 2  
Old 08-19-2008
Error

yes can you share what the problem you facing while reformatting?
# 3  
Old 08-19-2008
Thanks for the quick response. The email being sent is an automatic email that is sent when one of my order takers enters an order. The email that is sent includes all of the line items that are on the order and it looks like this:
Code:
 
Item Desc Qty Ord Ext Price Required Date Disposition
PRT KE54900 MAGNETIC BASE PROTRACTOR MI 1.00 EA 194.85 
PRT AL535244 2-11/16 5MT HS TS 24" DRILL 1.00 EA 610.60 
NIA 71203 5/8" 4FL HSCO SE 1-5/8LOC 1.00 EA 30.60 
BFL 10-10176 1-14 4FL H4 HAND TAPER 1.00 EA 54.34 
VAL 52286 PT542T 10.00 EA 36.50 
VAL 52332 PT818T 10.00 EA 36.50 
GEN 88CM TUNGSTEN CARBIDE PT SCRIBER 3.00 EA 22.02 
MAF 79000002 82DEG HSS CHATTERLESS 1.00 EA 97.66

(The formatting in this reply isn't quite working...), but essentially each line contains the Item Number, Description, Order Qty, Extended Price, Required Date and Line Disposition. The problem is that the alignment doesn't work because 'padding'/'leading spaces' have been removed by my software application, so the columns do not line up correctly.
So I would need to parse the fields in each line then somehow 'realign' them, possibly with a tab delimteter.

I hope that makes sense, if not, I can try to elaborate further.

Thanks,

Todd
# 4  
Old 08-21-2008
Code:
vnix$ column -t <<HERE
> Item Desc Qty Ord Ext Price Required Date Disposition
> PRT KE54900 MAGNETIC BASE PROTRACTOR MI 1.00 EA 194.85 
> PRT AL535244 2-11/16 5MT HS TS 24" DRILL 1.00 EA 610.60 
> NIA 71203 5/8" 4FL HSCO SE 1-5/8LOC 1.00 EA 30.60 
> BFL 10-10176 1-14 4FL H4 HAND TAPER 1.00 EA 54.34 
> VAL 52286 PT542T 10.00 EA 36.50 
> VAL 52332 PT818T 10.00 EA 36.50 
> GEN 88CM TUNGSTEN CARBIDE PT SCRIBER 3.00 EA 22.02 
> MAF 79000002 82DEG HSS CHATTERLESS 1.00 EA 97.66
> HERE
Item  Desc      Qty       Ord      Ext          Price    Required  Date   Disposition
PRT   KE54900   MAGNETIC  BASE     PROTRACTOR   MI       1.00      EA     194.85
PRT   AL535244  2-11/16   5MT      HS           TS       24"       DRILL  1.00         EA     610.60
NIA   71203     5/8"      4FL      HSCO         SE       1-5/8LOC  1.00   EA           30.60
BFL   10-10176  1-14      4FL      H4           HAND     TAPER     1.00   EA           54.34
VAL   52286     PT542T    10.00    EA           36.50
VAL   52332     PT818T    10.00    EA           36.50
GEN   88CM      TUNGSTEN  CARBIDE  PT           SCRIBER  3.00      EA     22.02
MAF   79000002  82DEG     HSS      CHATTERLESS  1.00     EA        97.66

The output is slightly too large for email (80 columns max recommended) but maybe you can take it from there.

Like the computer, we can only guess which fields are "Item" and which are "Desc"; the other parts may not be too hard to fix. If you know how many fields there are supposed to be and which may contain embedded spaces, maybe you can convert the spaces to something else before feeding the text to column, and convert back afterwards. Here's a proof of concept.

Code:
sed -e '1s/Qty Ord/Qty:Ord/' -e '1s/Ext Price/Ext:Price/' -e '1s/Required Date/Required:Date/' \
  -e '2,$s/ /:/g' -e '2,$s/:/ /' -e '2,$s/:\([^:]*\):\(..\):\([^:]*\):\([^:]*\)$/ \1 \2 \3 \4/' file |
column -t | sed 's/:/ /g'


Last edited by era; 08-21-2008 at 12:21 AM.. Reason: Add proof of concept
# 5  
Old 08-21-2008
Thanks for the suggestion, I thought something like this may be possible.

I do have the ability to put delimiters between the fields, I assume that would allow me to extract the fields in the correct place.

The much more difficult part of this is the fact that this information is being sent out as an email by my server. I need to reformat the data, then resend it out to an email address that is contained in another field in a different section of the email.

Lastly, there about 40 of these emails every hour that need to be parsed and 'resent' out.

Is it possible to build that sed code into some sort of routine that would do that process automatically when an email is received?

Thanks for the help and suggestions.

Todd
# 6  
Old 08-21-2008
Quote:
Originally Posted by toddk
I do have the ability to put delimiters between the fields,
In this case it is even a lot easier to do it. One will not have to rely on these complicated heuristics era had to resort to in absence of delimiters (great job, btw., era) but could use simply "cut" to split every line into fields, then use "printf" to output the fields in a formatted way.

Suppose your delimiter will be "|" (the pipe symbol) then your file would look like (just header and one line):

Code:
Item|Desc|Qty|Ord|Ext|Price|Required|Date|Disposition
PRT|KE54900 MAGNETIC BASE PROTRACTOR MI|1.00|EA|194.85||||

The reformatting is quite easily done now by the "cut"-utility: cut reads a line of text (aka "records") and splits it up into "fields" using a separator character. I show the logic in ksh here because this is easier to understand, the same functionality could be done in awk but the resulting code would be less intuitive.

Code:
cat /path/to/inputfile | while read line ; do
     item="$(print - $line | cut -d'|' -f1)"
     desc="$(print - $line | cut -d'|' -f2)"
     qty="$(print - $line | cut -d'|' -f3)"
     ord="$(print - $line | cut -d'|' -f4)"
     ....etc.....
     
     # output fields in a formatted way:
     printf  "%5s" "$item" >> /path/to/outputfile
     printf  " %20s" "$desc" >> /path/to/outputfile
     printf  " %4s" "$qty" >> /path/to/outputfile
     printf  " %5s" "$ord" >> /path/to/outputfile
     ....etc....
     printf  "\n" >> /path/to/outputfile
done

Quote:
The much more difficult part of this is the fact that this information is being sent out as an email by my server. I need to reformat the data, then resend it out to an email address that is contained in another field in a different section of the email.
Not at all difficult: suppose you have already extracted the adressing part and put it in variables:

Code:
cat /path/to/outputfile | mail -s "$subject" "$mailaddress"

How exactly the address and subject is to be extracted is depending on the form of the input file. Just give us an example and i am sure someone or other can work that one out.

Quote:
Lastly, there about 40 of these emails every hour that need to be parsed and 'resent' out.
This poses no problem. If there is a certain condition (for instance a file is produced by your software, etc.) to watch for the script i sketched out could run in a loop looking every x seconds for the condition to become true and than act accordingly, otherwise wait for another x seconds. 40 mails an hour should pose no problems even for the smallest p505 there is. The execution for such a script will typically take a fraction of a second.

I hope this helps.

bakunin
# 7  
Old 08-22-2008
Quote:
Originally Posted by toddk
Is it possible to build that sed code into some sort of routine that would do that process automatically when an email is received?
Sounds like you should look at procmail
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Makefile No rule to make target

I am trying to create a makefile to build a program and am getting the following error: make -f tsimplex.mk make: *** No rule to make target `/main/tsimplex_main.cpp', needed by `tsimplex_main.o'. Stop. OPSYS = $(shell uname -s ) TARGET = tsimplex ROOTDIR = ../../.. GTSDIR =... (1 Reply)
Discussion started by: kristinu
1 Replies

2. Programming

Issue with make, no rule to make target etc.

I have been trying to split up my src directory to clear out files that are not re-compiled very often. Now I have the following setup in my trunk, trunk/bld trunk/src/ trunk/src/src_server trunk/makefile.linux In the make file, I have compile rules SOURCELOC = src # compile src c++... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

3. UNIX for Dummies Questions & Answers

Difference between configure/make/make install.

Hi, While installation of apache on linux, we perform the below tasks. 1) Untar 2) configure 3) make 4) make install. I wanted to understand the difference and working of configure/make/make install. Can any one help me understanding this? Thanks in advance. (1 Reply)
Discussion started by: praveen_b744
1 Replies

4. Programming

compile fails in linux ... "No rule to make target" ... HELP

hello all, attached you can find a tool (written in C) that i really need to make it compile under linux i am able to compile and run it successfully in mac os x, but in linux the compilation fails the only thing that i did so far is to change the following #include <sys/malloc.h> to... (13 Replies)
Discussion started by: OneDreamCloser
13 Replies

5. Post Here to Contact Site Administrators and Moderators

Rule # 8

In light of this board's rule stating "no BSD vs. Linux vs. Windows or similar threads," is the following post legal (can I post it)? Hi. I'm thinking about obtaining a web server for business purposes and I want to learn to administer and maintain the server myself. I need to be able to use... (1 Reply)
Discussion started by: bluegospel
1 Replies

6. Solaris

Gani Network Driver Won't Install - make: Fatal error: Don't know how to make targ...

I attached a README file that I will refer to. I successfully completed everything in the README file until step 4. # pwd /gani/gani-2.4.4 # ls COPYING Makefile.macros gem.c Makefile Makefile.sparc_gcc gem.h Makefile.amd64_gcc ... (1 Reply)
Discussion started by: Bradj47
1 Replies

7. Linux

Error in issuing a make and make install

Hi, Recently I install a package and try to do a make and make install. However, in the make it gives me below error:- make:Nothing to be done for 'install-exec-am' make:Nothing to be done for 'install-data-am' Can anyone please explain to me what does this mean? I have been trying... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

8. UNIX for Dummies Questions & Answers

make and clean in a single rule in the makefile.

Hi, This stems from the following thread https://www.unix.com/showthread.php?t=18299 I have a makefile which makes either executables or a shared library. i.e. make -f unix.mak will create the executables and make -f unix.mak libolsv will create the shared library. Since these have to be... (4 Replies)
Discussion started by: vino
4 Replies
Login or Register to Ask a Question