list all file whose 3rd char is digit (or Nth position is digit)
what will be the required command?
list all file whose 3rd char is digit (or Nth position is digit)
what will be the required command?
ls ??[0-9]*
With an ERE (egrep or grep -E)
ls | egrep '^.{2}[0-9]'
^
beginning of line
.{2}
a character 2 times
[0-9]
a character in the range 0-9
Within " "
the shell substitutes $var
or ${var}
by its value, before it hands it to the egrep
num=2
ls | egrep "^.{$num}[0-9]"
Slightly different approach:
echo ??[0-9]* | tr " " "\n"
compgen -f -X '!??[0-9]*'
The simple "arguments to lines" command is printf
printf "%s\n" ??[0-9]*
But commands can overflow with "too many arguments".