Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Sed and Awk (http://www.programmingforums.org/forum22.html)
-   -   help needed urgently (http://www.programmingforums.org/showthread.php?t=3854)

rasha May 11th, 2005 8:01 AM

help needed urgently
 
I have file with 42 columns separated by |
Some lines start with number and some with "" and have "" in every field except in the last two columns (fields).
I would like to replace all fields containing "" in the lines not starting with numbers with the values in the corresponding fields in the closesd preceiding line starting with number except last two fields.

Here is the example of the file, but it will probably be badly wraped here due to the fact that lines are quite long.

1|" ALUMINIOS LA BLANCA S.L. (EN LIQUIDACION)"|" ALUMINIOS LA BLANCA S.L. (EN LIQUIDACION)"|"PG INDUSTRIAL ALDAYTURRIAGA"|"01400"|""|"AMURRIO"|0|"¡lava"|"SPAIN"|"+34 945/393428"|""|""|"B01190313"|0|"Sociedad limitada"|"11/2/1995"|"12/31/2002"|"Unquoted Company"|""|""|""|""|""|""|""|"FABRICACION Y VENTA DE VENTANAS, MAMPARAS, SEPARADORES, CIERRES, PUERTAS."|"2812"|"12/31/2002"|"U1"|"Unconsolidated Accounts"|"Uncons."|"Dissolution"|"7/9/2003"|618|""|""|"EUR"|0|1.000000000|580|"RODRIGUEZ GOMEZ CLEMENTE"|"Liquidator"
2|" CONSTRUCCIONES COBESAN 2000 S.L."|" CONSTRUCCIONES COBESAN 2000 S.L."|"GR RESIDENCIAL PALMERAS, 7"|"21720"|""|"ROCIANA DEL CONDADO"|0|"Huelva"|"SPAIN"|"+34 959/416156"|""|""|"B21308432"|0|"Sociedad limitada"|"12/11/2000"|"12/31/2002"|"Unquoted Company"|""|""|""|""|""|""|132|"CONSTRUCCION EN GENERAL, PROMOCION, COMPRAVENTA DE BIENES INMUEBLES"|"4521"|"12/31/2002"|"U1"|"Unconsolidated Accounts"|"Uncons."|"Active"|""|3946|""|"BENAVENTE BUENO MANUEL"|"EUR"|0|1.000000000|580|"BENAVENTE BUENO MANUEL"|"Member of the Board"
""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|"SANCHEZ GARCIA AMPARO"|"Member of the Board"
3|"0 A 24 MULTISERVICIO SOCIEDAD LIMITADA."|"0 A 24 MULTISERVICIO SOCIEDAD LIMITADA."|"CL PERIODISTA TEODORO LLORENTE, 4"|"46009"|""|"VALENCIA"|0|"Valencia"|"SPAIN"|"+34 96/3296309"|""|""|"B96918560"|0|"Sociedad limitada"|"10/22/1999"|"12/31/2002"|"Unquoted Company"|""|""|""|""|""|""|4|"LA PRESTACION DE LOS SERVICIOS DE CARPINTERIA, CERRAJERIA, FONTANERIA Y ELECTRICIDAD."|"4542"|"12/31/2002"|"U1"|"Unconsolidated Accounts"|"Uncons."|"Active"|""|504|""|"MOLINA AGUILAR JOSE LUIS"|"EUR"|0|1.000000000|580|"MOLINA AGUILAR JOSE LUIS"|"Sole Administrator"
4|"0 KM EXPRESS S.L."|"0 KM EXPRESS S.L."|"AV DE FUENTEMAR, 29"|"28820"|""|"COSLADA"|0|"Madrid"|"SPAIN"|"+34 91/6741111"|"+34 91/6739262"|""|"B81687428"|0|"Sociedad limitada"|"3/14/1997"|"12/31/2002"|"Unquoted Company"|""|""|""|""|""|""|33|"TRANSPORTE AEREO, MARITIMO Y TERRESTRE DE TODA CLASE DE MERCANCIAS A NIVEL NACIONAL E INTERNACIONAL."|"6340"|"12/31/2002"|"U1"|"Unconsolidated Accounts"|"Uncons."|"Active"|""|10637|"VILLANUEVA RODRIGUEZ URBANO JOSE"|"ALBINANA GONZALEZ FRANCISCO JAVIER"|"EUR"|0|1.000000000|580|"VILLANUEVA RODRIGUEZ URBANO JOSE"|"President of the Board"
""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|"ALBINANA GONZALEZ FRANCISCO JAVIER"|"Executive Director"
""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|""|"STOCCO SERGIO"|"Administrator"

rasha May 11th, 2005 11:07 AM

I have manged to solve the problem with following program
 
I have managed to solve the problem
:

awk -F"|" '{if ($2 !~"\"\"" )  {print $0; X=$1 "|" $2 "|" $3 "|" $4 "|" $5 "|" $6 "|" $7 "|" $8 "|" $9 "|" $10 "|" $11 "|" $12 "|" $13 "|" $14 "|" $15 "|" $16 "|" $17 "|" $18 "|" $19 "|" $20 "|" $21 "|" $22 "|" $23 "|" $24 "|" $25 "|" $26 "|" $27 "|" $28 "|" $29 "|" $30 "|" $31 "|" $32 "|" $33 "|" $34 "|" $35 "|" $36 "|" $37 "|" $38 "|" $39 "|" $40 "|" $41 } else {print X "|" $42 "|" $43}}' inputfile.txt > outputfile.txt

Infinite Recursion May 16th, 2005 9:39 AM

congrats


All times are GMT -5. The time now is 1:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC