I've been trying to figure out how to grep a line with only N occurrences of a character.
[root@example DIR]# grep -E "6{,1}" test.txt
6543
6625
6668
6868
6666
1161
What I want is for grep to print out the following:
[root@example DIR]# grep -E "6{,1}" test.txt
6543
1161
What am I missing?
With awk I'd:
$ awk '/6/&&!/6.*6/' file
6543
1161
It translates to grep
like:
$ grep 6 file | grep -v 6.*6
6543
1161
Edit:
@Sundeep's clever idea to use 6 as a field separator and to count the fields (see comments):
$ awk -F6 'NF==2' file
6543
1161
^ his comment below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With