Quantcast
Channel: Grep for a line containing only 5 or 6 numbers - Unix & Linux Stack Exchange
Browsing all 8 articles
Browse latest View live

Answer by JigarGandhi for Grep for a line containing only 5 or 6 numbers

I know I have not solved using sed or awk or any of shell commands, However tcl did work out well. I have kept the script simple and user friendly. elements like 4a abc etc will be taken care command...

View Article



Answer by Laurentiu Roescu for Grep for a line containing only 5 or 6 numbers

grep -E '^(\s*[0-9]+\s+){4,5}[0-9]+\s*$'

View Article

Answer by Stéphane Chazelas for Grep for a line containing only 5 or 6 numbers

awk '{l=$0; n = gsub(/[0-9]+/, "", l)}; n == 5 || n == 6' (same principle as in Joseph's answer)

View Article

Answer by user78605 for Grep for a line containing only 5 or 6 numbers

A way with awk that is customisable for different numbers of fields. Also whitespace does not matter. awk 'NF~/^(5|6)$/{x=0;for(i=1;i<=NF;i++)x+=($i~/^[0-9]+$/)}x==NF' file This checks the number of...

View Article

Answer by cuonglm for Grep for a line containing only 5 or 6 numbers

Another perl: $ perl -MList::Util=first -Tnle ' s/^\s+|\s+$//g; @e = split /\s+/; print if @e == 5 || @e == 6 and !first {/\D/} @e; ' file 10 2 12 1 13 Explanation s/^\s+|\s+$//g trim the line. @e =...

View Article


Answer by muru for Grep for a line containing only 5 or 6 numbers

grep -E '[0-9]{5}' is looking for numbers with at least 5 digits. What you need is 5 numbers with at least one digit: grep -E '[0-9]+([^0-9]+[0-9]+){4}' [0-9]+ - a number of at least one digit...

View Article

Answer by Joseph R. for Grep for a line containing only 5 or 6 numbers

I would go with something a little more powerful than grep. This can do it in perl: perl -ne 'print if s/\d+/$&/g == 5' your_file The regex substitution replaces all groups of one or more digits...

View Article

Grep for a line containing only 5 or 6 numbers

How would you grep for a line containing only 5 or 6 numbers? Something like this. case 1 (has leading space) 10 2 12 1 13 case 2 (no leading space) 1 2 3 4 5 6 I thought something like this would...

View Article

Browsing all 8 articles
Browse latest View live




Latest Images