Shell Scripting – 4

Filename Substitution

  1. The Asterisk

  2. The Question mark

  3. The Square Brackets

  1. The Asterisk:

    The Asterisk(*) is one of the powerful feature in *nix used for file name substitutions.If you know the file starting and ending positions but not the complete file name you can use this by concatenating with the part of file name you know even you can use Asterisk as argument to do a function on multiple files.

    1. [shell_test@localhost test]$ ls
      page1 page2 page3 page4
      [shell_test@localhost test]$ cat *
      The only thing that scares me more than space aliens is the idea that there aren’t any space aliens. We can’t be the best that creation has to offer. I pray we’re not all there is. If so, we’re in big trouble.
      – Ellen DeGeneres
      I can win an argument on any topic, against any opponent. People know this, and steer clear of me at parties. Often, as a sign of their great respect, they don’t even invite me.
      – Dave Barry
      A good friend can tell you what is the matter with you in a minute. He may not seem such a good friend after telling.
      – Arthur Brisbane

      The only thing that scares me more than space aliens is the idea that there aren’t any space aliens. We can’t be the best that creation has to offer. I pray we’re not all there is. If so, we’re in big trouble.
      – Ellen DeGeneres
      I can win an argument on any topic, against any opponent. People know this, and steer clear of me at parties. Often, as a sign of their great respect, they don’t even invite me.
      – Dave Barry
      A good friend can tell you what is the matter with you in a minute. He may not seem such a good friend after telling.
      – Arthur Brisbane

      * క్షణం తీరికలేదు దమ్మిడి ఆదాయం లేదు
      * క్షేత్రమెరిగి విత్తనం వెయ్యాలి, పాత్రమెరిగి దానం వెయ్యాలి
      * క్షేమంగా పోయి లాభంగా రండి
      * హనుమంతుడి ముందా కుప్పిగంతులు
      * హనుమంతుడు… అందగాడు…
      * హరిశ్చంద్రుని లెంపకాయ కొట్టి పుట్టినాడు
      * హాస్యగాణ్ణి తేలుకుట్టినట్లు
      [shell_test@localhost test]$

    2. [shell_test@localhost test]$ ls
      page1 page2 page3 test_page
      [shell_test@localhost test]$ cat pa*
      The only thing that scares me more than space aliens is the idea that there aren’t any space aliens. We can’t be the best that creation has to offer. I pray we’re not all there is. If so, we’re in big trouble.
      – Ellen DeGeneres
      I can win an argument on any topic, against any opponent. People know this, and steer clear of me at parties. Often, as a sign of their great respect, they don’t even invite me.
      – Dave Barry
      A good friend can tell you what is the matter with you in a minute. He may not seem such a good friend after telling.
      – Arthur Brisbane

      The only thing that scares me more than space aliens is the idea that there aren’t any space aliens. We can’t be the best that creation has to offer. I pray we’re not all there is. If so, we’re in big trouble.
      – Ellen DeGeneres
      I can win an argument on any topic, against any opponent. People know this, and steer clear of me at parties. Often, as a sign of their great respect, they don’t even invite me.
      – Dave Barry
      A good friend can tell you what is the matter with you in a minute. He may not seem such a good friend after telling.
      – Arthur Brisbane

      * క్షణం తీరికలేదు దమ్మిడి ఆదాయం లేదు
      * క్షేత్రమెరిగి విత్తనం వెయ్యాలి, పాత్రమెరిగి దానం వెయ్యాలి
      * క్షేమంగా పోయి లాభంగా రండి
      [shell_test@localhost test]$

  2. The Question mark

    If you want to perform any action on file with name only one character what will you do?
    Obviously the answer is ? the question mark. and if only files with file name two characters ?? and so on .If you want to work on files with more than two characters use ??* so on

    1. [shell_test@localhost test]$ ls -l
      total 16
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 a
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 aa
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 b
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 cc
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 dd
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 ee
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 pa
      -rw-rw-r–. 1 shell_test shell_test 561 2009-11-14 08:26 page1
      -rw-rw-r–. 1 shell_test shell_test 567 2009-11-14 08:27 page2
      -rw-rw-r–. 1 shell_test shell_test 331 2009-11-14 08:27 page3
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 pb
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 pc
      -rw-rw-r–. 1 shell_test shell_test 337 2009-11-14 08:28 test_page
      [shell_test@localhost test]$ echo ?
      a b
      [shell_test@localhost test]$
    2. [shell_test@localhost test]$ echo ??
      aa cc dd ee pa pb pc
      [shell_test@localhost test]$
    3. [shell_test@localhost test]$ echo ??*
      aa cc dd ee pa page1 page2 page3 pb pc test_page
      [shell_test@localhost test]$
  3. The Square Brackets

      The square brackets can be used in two different ways one is to index all files with starting or ending with only one character among the characters listed or character sequence in concatenation with the (*)

    1. [shell_test@localhost test]$ ls -l
      total 16
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 a
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 aa
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 b
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 cc
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 dd
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 ee
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 pa
      -rw-rw-r–. 1 shell_test shell_test 561 2009-11-14 08:26 page1
      -rw-rw-r–. 1 shell_test shell_test 567 2009-11-14 08:27 page2
      -rw-rw-r–. 1 shell_test shell_test 331 2009-11-14 08:27 page3
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 pb
      -rw-rw-r–. 1 shell_test shell_test 0 2009-11-14 08:45 pc
      -rw-rw-r–. 1 shell_test shell_test 337 2009-11-14 08:28 test_page
      [shell_test@localhost test]$ ls [abc]*
      a aa b cc
      [shell_test@localhost test]$
    2. [shell_test@localhost test]$ ls
      1 2 3 4_test a aa b cc dd ee pa page1 page2 page3 pb pc test_page
      [shell_test@localhost test]$ ls [a-z]*
      a aa b cc dd ee pa page1 page2 page3 pb pc test_page
      [shell_test@localhost test]$

next

స్పందించండి

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / మార్చు )

Twitter picture

You are commenting using your Twitter account. Log Out / మార్చు )

Facebook photo

You are commenting using your Facebook account. Log Out / మార్చు )

Google+ photo

You are commenting using your Google+ account. Log Out / మార్చు )

Connecting to %s