Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to truncate file by number of characters in a specific column

I have 4 columns , separated by a ;.

Some lines in the 3rd or the 4th column, are huge with more than 10000 characters.

How would you remove the lines , regardless of which columns , where the length of one specific column goes beyond 10000 characters?

I tried with that

awk '{i += (length() + 1); if (i <= 10000) print $ALL}' 

But it is taking the whole file and not only specific column and I want the length of the column, regardless if it is the 3rd or the 4th or maybe both.

TIA

like image 667
Andy K Avatar asked Dec 03 '22 18:12

Andy K


1 Answers

All you need is:

$ cat file
a;b;c
d;efg;h
i;j;klm
opqr;s;t
uv;wx;yz

$ egrep -v '[^;]{3}' file
a;b;c
uv;wx;yz

$ awk '!/[^;]{3}/' file
a;b;c
uv;wx;yz

$ sed -r '/[^;]{3}/d' file
a;b;c
uv;wx;yz

Change the "3" to 1001 or whatever...

like image 92
Ed Morton Avatar answered Dec 26 '22 11:12

Ed Morton