User Tools

Site Tools


k19:k19.6:k19.6.1:start

19.6.1 Using wildcards in a console

Wildcards or joker characters such as * or ? denote a placeholder for other characters and you are probably familiar with these from working in a console.

In the following table, wildcards and their extensions are described and the placeholder properties are mentioned:

WildcardDescription: Matches exactly … or is placeholder for exactly …
*One or more characters
?One character
[mMbB]One character from the character set
[a-d]One character from the given range
[!mMbB]Any character that is not in the character set
[!a-d]Any character that is not in the specified range
{txt,log,csv}One of the three 'words' in the comma-separated list

Table 19.6.1.1: Often used wildcards in a console

19.6.1.1 Example 1

Searches for all files in the current directory

  • that begin with the letter p or P [pP] and
  • which are followed by several characters * and
  • whose extension is exactly 3 characters long ??? :
  hans@linux:~$ ls -l [pP]*.???
  -rwxrwxrwx 1 hans hans   467 Dez 26 20:30 parametertest.sh~
  -rw------- 1 hans hans     0 Okt 27 19:54 perl.cgi
  -rw------- 1 hans hans   225 Mai 11  2011 pgausgabe.sql

19.6.1.2 Further examples

  hans@linux:~$ ls -l [m]*.*[~]
  -rwx--x--x 1 hans hans  270 Dez 29 14:41 myName.script~
  -rw------- 1 hans hans 3022 Dez 29 16:00 mysql.gbs~
  hans@linux:~$ ls -l [kKmM]*.gb{s,w}
  -rw------- 1 hans hans 1616 Mai 14  2012 kontakt.gbw
  -rwx--x--x 1 hans hans 2018 Jan  3  2012 m.gbs
  -rw------- 1 hans hans 1984 Jan  3  2012 m.gbw
  -rwx--x--x 1 hans hans 3022 Dez 29 16:00 mysql.gbs

The console editor sed, through the use of regular expressions - in conjunction with the SHELL and EXEC instructions - offers extensive possibilities for conveniently working with text files and and their contents (strings). The following example is intended to demonstrate the power of the sed programme:

  hans@linux:~$ sed 's/\bProgramm\b/Projekt/g' --in-place=.bak $HOME/a_sed.txt

What does this cryptic-looking line do? In the file a_sed.txt, the (isolated) word programme globally (/g) - i.e. in the entire text content - is to be replaced by the word project and the original file with the extension .bak is to be saved in the file with the file name originalfilename.bak.

If such a one-liner can inspire you, then this is the right motivation to deal (more intensively) with regular expressions and their use in Gambas projects.

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k19/k19.6/k19.6.1/start.txt · Last modified: 14.10.2023 by emma

Page Tools