1

Lets say Im having the following entries:

*ARTNR;*BESTAND;*HERSTARTNR;*WG;*WG2;*LWG;*LWG2
1000;2758;;PAS;;Passive Bauelemente;
5800;0;;PAS;MIC;Passive Bauelemente;Microchip Technology
5801;0;;AKT;AMP;Aktive Bauelemente;TE connectivity
5802;0;;PAS;;Passive Bauelemente;
5803;0;"PDZ 4,3B  7""SOD323";AKT;;Aktive Bauelemente;
5804;0;;MEC;HON;Elektromechanik;Honeywell
5805;0;;MEC;;Elektromechanik;
5806;0;;MEC;;Elektromechanik;
5807;0;;MEC;HON;Elektromechanik;Honeywell
5809;0;;AKT;ORS;Aktive Bauelemente;Osram Opto Semiconductors
5810;0;61240090;MEC;;Elektromechanik;
5811;0;AT89C55WD-24PU;AKT;ATM;Aktive Bauelemente;Atmel
5815;0;;MEC;;Elektromechanik;
5816;0;;MEC;;Elektromechanik;

I now want to remove all rows that are empty on the colum, *HERSTARTNR like the first row. Is this possible with a batch script?

Thank you

1
  • it's very easy with python Commented Mar 6, 2013 at 13:43

2 Answers 2

3

To preserve the header row, test for non-semicolons in the first two columns.

In Windows:

findstr /v "^[^;]*;[^;]*;;" old.csv >new.csv

In *nix:

grep -P -v '^[^;]*;[^;]*;;' old.csv >new.csv

Linux example:

rojo@pico:~$ grep -P -v '^[^;]*;[^;]*;;' old.csv > new.csv
rojo@pico:~$ cat new.csv
*ARTNR;*BESTAND;*HERSTARTNR;*WG;*WG2;*LWG;*LWG2
5803;0;"PDZ 4,3B  7""SOD323";AKT;;Aktive Bauelemente;
5810;0;61240090;MEC;;Elektromechanik;
5811;0;AT89C55WD-24PU;AKT;ATM;Aktive Bauelemente;Atmel

Windows example:

C:\Users\me\Desktop>findstr /v "^[^;]*;[^;]*;;" old.csv > new.csv
C:\Users\me\Desktop>type new.csv
*ARTNR;*BESTAND;*HERSTARTNR;*WG;*WG2;*LWG;*LWG2
5803;0;"PDZ 4,3B  7""SOD323";AKT;;Aktive Bauelemente;
5810;0;61240090;MEC;;Elektromechanik;
5811;0;AT89C55WD-24PU;AKT;ATM;Aktive Bauelemente;Atmel
Sign up to request clarification or add additional context in comments.

Comments

0

Will this do the trick?

perl -ne 'print unless /^\d+;\d+;;/' file.csv

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.