Newbie question, looking for pl examples that I can work from

T

tpcolson

I'm no programmer by any means...I have 600 files that I have to do a
lot of repetive stuff to (GPS data that has to be formatted for upload
into the NGS database).

What I'm looking to automate is:

Step 1: Copy characters in (space?Line) 12-15 in row 1 and characters
in (space?line?) 4-7 in row 12 -> and write these 8 characters to
(space?line) 2-9 in row 50 (which allready has text there, all 0's,
which needs to be overwritten.

Step 2: Copy characters in (space?Line) 12-15 in row 1 and characters
in (space?line?) 4-7 in row 13 -> and write these 8 characters to
(space?line) 2-9 in row 51 (which allready has text there, all 0's,
which needs to be overwritten.


Step 3: Copy characters in (space?Line) 12-15 in row 1 and characters
in (space?line?) 4-7 in row 14 -> and write these 8 characters to
(space?line) 2-9 in row 52 (which allready has text there, all 0's,
which needs to be overwritten.


Step 4: Beginning at row 53 (this gets hairy) put a carraige return
BEFORE the second letter "D" that is encountered and every D after that
(about 9 "D"s). Can't look for all D's in the whole txt file, as there
are lots that need to stay where they are.

Step 5: Copy rows 50-5x to a new txt file.

Step 6: run this pl script against another input file, and APPEND
results of step 5 to the txt file created in step 5.

Posted below are before and after examples:

Before

FILE: 21171886.DAT 000002776

NGS OPUS-RS SOLUTION REPORT
========================
..
..
..
BASE STATIONS USED
PID DESIGNATION LATITUDE LONGITUDE
DISTANCE(m)
DG5940 VALY MASSIE CORS ARP N372232.071 W0790735.675
139185.9
AM7013 HILB HILLSBOROUGH CORS ARP N360310.178 W0790609.101
12932.8
AJ2913 RALR RALEIGH CORS ARP N354712.852 W0783819.411
49254.9
..
..
..
Axx2006 7 72006 0 7
B2006 7 017 02006 7 017 0 3 rsgps 0.90IGS
Iant_info.003 NGS
C00040001 -276294327 32 790799428 150 1111562005 114
C00040002 -89599763 31 -66248694 149 -65641692 114
C00040003 354507175 32 -155059133 149 -304772514 114
D 1 2 -8885611 1 3 9234127 1 4 9421130 1 5 -8394382 1 6
8759577 D 1 7 9196876 1 8 -8355813 1 9 8733047 2 3 -9759412
2 4 -8435147 D 2 5 9461764 2 6 -9273033 2 7 -8234550 2 8
9424027 2 9 -9247586 D 3 4 8810457 3 5 -9302342 3 6 9503507
3 7 8686579 3 8 -9280962 D 3 9 9489121 4 5 -8874091 4 6
9265782 4 7 9355880 4 8 -8438250 D 4 9 8801376 5 6 -9783679
5 7 -8392435 5 8 9502704 5 9 -9308397 D 6 7 8739195 6 8
-9303254 6 9 9504962 7 8 -8870240 7 9 9245156 D 8 9 -9783610


After:

Axx2006 7 72006 0 7
B2006 7 017 02006 7 017 0 3 rsgps 0.90IGS
Iant_info.003 NGS
C18865940 -276294327 32 790799428 150 1111562005 114
C18867013 -89599763 31 -66248694 149 -65641692 114
C18862913 354507175 32 -155059133 149 -304772514 114
D 1 2 -8885611 1 3 9234127 1 4 9421130 1 5 -8394382 1 6
8759577
D 1 7 9196876 1 8 -8355813 1 9 8733047 2 3 -9759412 2 4
-8435147
D 2 5 9461764 2 6 -9273033 2 7 -8234550 2 8 9424027 2 9
-9247586
D 3 4 8810457 3 5 -9302342 3 6 9503507 3 7 8686579 3 8
-9280962
D 3 9 9489121 4 5 -8874091 4 6 9265782 4 7 9355880 4 8
-8438250
D 4 9 8801376 5 6 -9783679 5 7 -8392435 5 8 9502704 5 9
-9308397
D 6 7 8739195 6 8 -9303254 6 9 9504962 7 8 -8870240 7 9
9245156
D 8 9 -9783610


I would greatly appreciate it if someone could post a website with some
basic examples that do line/row/column copy and paste...I've been
looking all day and can't make heads or tails of it....

Thanks

Tom- North Carolina State University/NC Geodetic Survey.
 
D

Dr.Ruud

(e-mail address removed) schreef:
I would greatly appreciate it if someone could post a website with
some basic examples that do line/row/column copy and paste...I've been
looking all day and can't make heads or tails of it....

perldoc -q fixed-record-length
 
J

John W. Krahn

I'm no programmer by any means...I have 600 files that I have to do a
lot of repetive stuff to (GPS data that has to be formatted for upload
into the NGS database).

What I'm looking to automate is:

Step 1: Copy characters in (space?Line) 12-15 in row 1 and characters
in (space?line?) 4-7 in row 12 -> and write these 8 characters to
(space?line) 2-9 in row 50 (which allready has text there, all 0's,
which needs to be overwritten.

Step 2: Copy characters in (space?Line) 12-15 in row 1 and characters
in (space?line?) 4-7 in row 13 -> and write these 8 characters to
(space?line) 2-9 in row 51 (which allready has text there, all 0's,
which needs to be overwritten.

Step 3: Copy characters in (space?Line) 12-15 in row 1 and characters
in (space?line?) 4-7 in row 14 -> and write these 8 characters to
(space?line) 2-9 in row 52 (which allready has text there, all 0's,
which needs to be overwritten.

For example:

while ( my $row = <> ) {
if ( $. == 1 ) {
$prefix = substr $row, 11, 4;
}
if ( $. == 12 || $. == 13 || $. == 14 ) {
push @suffix, substr $row, 2, 4;
}
if ( $. == 50 || $. == 51 || $. == 52 ) {
substr $row, 1, 8, $prefix . shift @suffix;
}
}

Step 4: Beginning at row 53 (this gets hairy) put a carraige return
BEFORE the second letter "D" that is encountered and every D after that
(about 9 "D"s). Can't look for all D's in the whole txt file, as there
are lots that need to stay where they are.

Step 5: Copy rows 50-5x to a new txt file.

This is the tricky part. It depends on what comes before and after this block
of text (your example elides this information.) You may be able to use
paragraph mode if this block is preceeded and followed by blank lines or else
you need some way to identify with certainty the beginning and end of the block.

For example:

if ( 50 .. /end of block/ ) {
$block .= $row;
}
if ( /end of block/ ) {
$block =~ s/(?<=\d) +(?=D \d)/\n/g;
}

Step 6: run this pl script against another input file, and APPEND
results of step 5 to the txt file created in step 5.

open my $out, '>>', 'new txt file' # open in append mode
or die "Cannot open 'new txt file' $!";




John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,379
Messages
2,571,929
Members
48,766
Latest member
LelaSliva

Latest Threads

Top