0

Display all lines of the file /etc/ssh/sshd_config starting with a letter.

include capital letters as well

below is what i tried

#!/bin/bash
grep -i 'n*' /etc/ssh/sshd_config
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • 1
    This isn't a question. What went wrong when you tried? (Mind, there _are_ some obvious answers to "what went wrong", but you should be describing how actual and expected behavior differ in the question, not making us infer from your code what question you mean to ask). – Charles Duffy Feb 14 '23 at 00:18
  • First: `n*` is not "any string that starts with n" in regex syntax -- as the "grep lines that start with a specific string" duplicate tells you, it's "any string that contains zero or more `n`s anywhere in its contents", which is of course any string at all. You're thinking *glob* syntax, but globs and regular expressions are two different things; a regex for any string that starts with `n` is `^n` – Charles Duffy Feb 14 '23 at 00:21
  • Second, as the linked duplicate on making grep case-insensitive tells you, you can either use `[Nn]` to match either `n` or `N`, or you can use the `-i` argument to grep to make it case-insensitive outright. – Charles Duffy Feb 14 '23 at 00:22

1 Answers1

0

Like this:

grep '^[[:alpha:]]' /etc/ssh/sshd_config
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • Heh. I read "a letter" to mean "a specific letter", but this interpretation makes more sense as a practical exercise rather than something homework-esque. – Charles Duffy Feb 14 '23 at 00:24
  • That said, `'^[[:alpha:]]'` is better practice -- remains accurate across locale and character-collation-order settings. – Charles Duffy Feb 14 '23 at 00:25
  • OP asked letters, not also digits – Gilles Quénot Feb 14 '23 at 00:27
  • @GillesQuenot, `[[:alpha:]]` _is_ only letters. To have both letters and digits would be `[[:alnum:]]` instead. But what counts as a "letter" is dependent on what part of the world you're in; so is whether there are any letters after `z`, and, for that matter, whether `b` is inside the range `A-Z` (some collation orders are AaBbCc...Zz, others are ABC...Zabc...z, others are abc...zABC...Z, etc) – Charles Duffy Feb 14 '23 at 02:08
  • Ah yes, tired, I was wrong. Post edited accordingly. – Gilles Quénot Feb 14 '23 at 07:35