Unix Shell comnand Template for displaying files expects any file from the template

I have the following command to list all files from cat1 to cat5

#ls cat[1-5]

What changes do I need to make in the above command to list all files except cat3

The output should be cat1 cat2 cat4 cat5

I am also trying to list files from cat1 to cat10 using ls cat[1-10], but only showing cat1 in the output

+3
source share
5 answers

This way you can exclude any list of characters:

ls cat[^3]
+2
source
ls | sed -e 's/\<cat3\>//g'

This sequence of commands can lead to a result. where cat3 is the name of the file.

0

.

  • ls cat [1245]
  • ls cat [1-5] | grep -v cat3
0

:

printf "%s\n" cat{1,2,4,5}
0

The problem is that you are using regular expressions. Thus, it cat[1-10]means: all files with the names cat0 and cat1, since you specify only these two characters inside the brackets (the regular expression does not know the number, only characters and character ranges).

To display everything from 0 to 99999 ... you can do the following:

# ls cat[0-9]*

For more regular expressions in bash, you can check out some docs: http://linux.die.net/Bash-Beginners-Guide/sect_04_01.html

0
source

All Articles