I survived another problem attack from the dark forces of Digital Unix
thanks to:
Dr. Tom Blinn (He suggested awk - unfortunately I'm hopeless with it)
tpb_at_zk3.dec.com
John K. Peterson (Too bad we don't use perl - he gave a script to solve
this)
jkpeters_at_acs2.byu.edu
Special thanks to:
Andrew L. Weston (He supplied an example script - It worked perfect,
Andrew)
andreww_at_adacel.com.au
Andrew's script:
#!/bin/sh
# Define variables
IN_FILE=test.txt
OUT_FILE=out.txt
# First we will insert a line of the form:
# 12 <entry number>
# after every 11value entry.
awk 'BEGIN { entry_counter = 1 }
{
firstnumber=substr($1,1,2);
if ( firstnumber == 11 )
{
print $0;
printf("12 %s\n",entry_counter);
entry_counter++
}
else
{ print $0 }
} ' $IN_FILE > $OUT_FILE
-------- end
This will insert the entry number preceeded by a 12 and space for the
file. You have not defined where the phone numbers would be stored.
If it was in a file it would help if you could assume that it is in the
same order as the databse file. In this case one idea I have is to:
loop for each entry (1 to total). In each iteration:
- copy the contents before this entry to a temp file,
- extract the current entry number from the list of numbers file,
- Construct the required line and appent to temp file,
- Append the remaining entries,
- copy the temp file to the input file.
If you simply want standard text then replace the line:
printf("12 %s\n",entry_counter);
with
printf("12the text\n");
Original question:
-------------------
> I have a file consisting of different values where each value represents
> a record type eg value 10 = name, value 11 = address (up to value 81).
> These values 10 to 81 represent data per customer and the file contains
> ~ 2000 customers.
> The file layout looks as follows:
>
> 10Mr. Joe Average
> 11P.O. Box 12345
> 13City
> 14Zip
> .
> .
> .
> 81Date
>
> I want to insert a value 12 with text (e.g telephone number) between
> every occurence of value 11 and 13 in the file.
>
> Any suggestions? We are running DU3.2 on Alpha 2100 servers.
Thank you once more
JC Faul
Received on Wed Nov 05 1997 - 08:27:46 NZDT