Sponsored Content
Top Forums Shell Programming and Scripting To make sure I don't violate rule #7 Post 302227704 by bakunin on Thursday 21st of August 2008 07:12:36 PM
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
 

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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
All times are GMT -4. The time now is 07:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy