Reputation: 3709
I need to remove lines from a file while contents on lines are tab delimited. - I need to first split the line using tab, then compute the length of the 3rd segment. - If the length is greater than say 1000, i will remove that line from the file.
I want to use sed and awk, but it's hard to get a quick start. Anyone can help? :)
Thanks a lot in advance!
Upvotes: 2
Views: 281
Reputation: 3709
I figured it out...
awk '{p = split($0,a,"\t"); if (length(a[3]) < 1000) print $0}' test.txt > out.txt
or awk -F '\t' '{if (length($3) < 1000) print $0}' test.txt > out.txt
Upvotes: 1
Reputation: 37298
awk -F"\t" 'length($3) < 1001{print}' file > outFile
-F"\t"
says split lines o tab, then print lines where the size (length) of the 3rd field is less than 1001.
I hope this helps.
Upvotes: 6