tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: Insert row
@ 1997-11-05  7:18 jfaul
  0 siblings, 0 replies; only message in thread
From: jfaul @ 1997-11-05  7:18 UTC (permalink / raw)
  To: tru64-unix-managers

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@zk3.dec.com

John K. Peterson (Too bad we don't use perl - he gave a script to solve
this)
jkpeters@acs2.byu.edu

Special thanks to:

Andrew L. Weston  (He supplied an example script - It worked perfect,
Andrew)
andreww@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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-11-05  7:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-11-05  7:18 SUMMARY: Insert row jfaul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox