Skip to main content
Welcome guest. | Register | Login | Post

Suppress Lines Too Short

4 replies [Last post]
supermike's picture
Offline
Joined: 2006-02-17

From Bash, core tools, and GNU tools (and I mean a default install like Ubuntu Breezy), what is a way to suppress the display of lines that are not of a fixed length? For instance, if the line is 24 chars, it's fine. But if it's less than 24 chars, that's a line I want to supress when catting a file.

For now, I'm going to do this with PHP.

 

tbuitenh's picture
Offline
Joined: 2005-12-21
awk. You will want to use

awk. You will want to use something along the lines of

if [ length($0) > 24 ] then { print $0 }

(the above is probably not correct, I never seriously used awk, and last time was four years ago, however IIRC $0 is the whole line and I'm sure there is a length function.

You could also use the regular expression .........................* (25 dots and an asterisk) with either awk or sed, but that's just silly. 

tbuitenh's picture
Offline
Joined: 2005-12-21
Actually, the regular

Actually, the regular expression is not such a bad idea after all. You could use

cat file | grep ........................ > file2

(24 dots) 

free-zombie's picture
Offline
Joined: 2006-03-08
.{24}   is shorter

.{24}

 

is shorter

tbuitenh's picture
Offline
Joined: 2005-12-21
Good point. Never needed to

Good point. Never needed to count anything in regexes...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.