[Omaha.pm] Another one-liner - whack a database unload

Jay Hannah jay at jays.net
Tue Mar 29 15:00:42 PST 2005


PROBLEM

Given a file, orphan.unl, that looks like this:

 >head -3 orphan.unl
11832|704402|PARKWE|L|GNRMSG||1004792774||DMC|2005-03-29  
10:50:04.37500|0|0|PRO-PARKWEACT-1004792774TYP-FINO-1STA-ATOP-FLAG  
MESSAGEFLG-20050329000000TXT-REQ: RQ NSRM KING TA  
RATE:FDT-20050328101854FCL-LAJONEXDT-XCL-TOW-CIP-CBP-PLC-WCA-RTC-URG- 
NCLN-CLO-CPH-EDT-20050330000000DEP-|
11834|704402|PARKWE|L|GNRSPE||1004792774||DMC|2005-03-29  
10:50:05.32800|0|0|PRO-PARKWEACT-1004792774ITN-1COD-S2FRD 
-20050329000000TOD-20050330000000AMT-0STA-C|
11840|704402|PARKWE|L|GNRSPE||1004792774||DMC|2005-03-29  
10:50:07.29600|0|0|PRO-PARKWEACT-1004792774ITN-2COD-KINGFRD 
-20050329000000TOD-20050330000000AMT-0STA-C|

Turn the leading digits into a single 0.

SOLUTION

 >cat orphan.unl | perl -ne "s/^\d+/0/; print" > orphan_new.unl

All done. Observe:

 >head -3 orphan_new.unl
0|704402|PARKWE|L|GNRMSG||1004792774||DMC|2005-03-29  
10:50:04.37500|0|0|PRO-PARKWEACT-1004792774TYP-FINO-1STA-ATOP-FLAG  
MESSAGEFLG-20050329000000TXT-REQ: RQ NSRM KING TA  
RATE:FDT-20050328101854FCL-LAJONEXDT-XCL-TOW-CIP-CBP-PLC-WCA-RTC-URG- 
NCLN-CLO-CPH-EDT-20050330000000DEP-|
0|704402|PARKWE|L|GNRSPE||1004792774||DMC|2005-03-29  
10:50:05.32800|0|0|PRO-PARKWEACT-1004792774ITN-1COD-S2FRD 
-20050329000000TOD-20050330000000AMT-0STA-C|
0|704402|PARKWE|L|GNRSPE||1004792774||DMC|2005-03-29  
10:50:07.29600|0|0|PRO-PARKWEACT-1004792774ITN-2COD-KINGFRD 
-20050329000000TOD-20050330000000AMT-0STA-C|

 >wc -l orphan*
      899 orphan.unl
      899 orphan_new.unl

Yay!

What's the point? orphan.unl was a database unload, and we needed to  
set the serial/autonumber column (the first column) value to 0 on every  
row so the database would assign the ID automatically.

j



More information about the Omaha-pm mailing list