need AWK help: lowercase, trim trailing spaces
Mario Dona
mario at wjvax.UUCP
Sat Apr 20 05:06:16 AEST 1991
HELP! I have a situation that just cries out for an awk solution, however
I'm at a loss over some minor, but important details. I have a list of
companies that need to be preprocessed before sending them to our typing
department. A simplified portion of the input file as follows:
COMPANY1 2800 FULLING P O BOX 3608 HARRISBURG PA 17105
COMPANY2 500 ELM MILWAUKEE WI 53122
COMPANY3 13500 CENTRAL P O BOX 655303 DALLAS TX 75265-5303
^ ^ ^ ^ ^
| | | | |
1 11 30 47 71
My mission, which I chose to accept, was to reformat the list so that it looks
like this:
Company1
28 Fulling
P O Box 3608
Harrisburg PA 17105
Company2
500 Elm
Milwaukee WI 53122
Company3
13500 Central
P O Box 655303
Dallas TX 75265-5303
Using the SUBSTR function to get the parts I want was trivial; the problem
is, I can't figure out:
1. How to prevent blank lines from printing if there is nothing to print
(e.g. the second address in COMPANY2 above).
2. How to concatenate the city and zip fields as shown.
3. If a word is greater than 2 characters, lowercase all letters
except for the first character (this is to keep state capitols
capitalized).
My feeble attempt so far is shown below. If anyone has any ideas, I'd be
much obliged.
BEGIN {
RS="\n"
}
{
name=substr($0,1,10)
address1=substr($0,11,19)
address2=substr($0,30,17)
city=substr($0,47,24)
zip=substr($0,71,10)
printf("%s\n%s\n%s\n%s\n%s\n\n", name, address1, address2, city, zip)
}
Mario Dona
...!{ !decwrl!qubix, ames!oliveb!tymix, pyramid}!wjvax!mario
The above opinions are mine alone and not, in any way, those of WJ.
More information about the Comp.unix.questions
mailing list