Prev: Use shell command to judge whether a file is in pdf format or not.
Next: [[:space:]] and [ \t ].
From: mop2 on 16 Feb 2010 10:30 On Tue, 16 Feb 2010 12:15:29 -0200, Hongyi Zhao <hongyi.zhao(a)gmail.com> wrote: > On Tue, 16 Feb 2010 05:25:55 -0800 (PST), Janis > <janis_papanagnou(a)hotmail.com> wrote: > >> $ grep '[ \t]' <<< $'\v' | od -c >> 0000000 >> >> $ grep '[[:space:]]' <<< $'\v' | od -c >> 0000000 \v \n >> 0000002 > > Excellent examples but obscure for newbie like me to figure out its > meaning, especially the latter part of your codes: <<< $'\v' | od > -c. > Any hints? Yes! To shell $'\v' is a byte, as '\n' is. Don't be root to play and shell can teach a lot with a relatively low risk. For example, try in the command line: echo -e 'a\nb' # and see Idem for: echo -e 'a\vb' "od" is to shell an extern command. In the command line you can try: od --help Or/and: man od You can try previously commands with "echo" before it, to a preview. For example: for i in [??][??]*.pdf;do echo something $i;done If you see what you want, then you can remove the 'echo' word and the command will be executed.
From: Janis on 16 Feb 2010 11:34 On 16 Feb., 15:15, Hongyi Zhao <hongyi.z...(a)gmail.com> wrote: > On Tue, 16 Feb 2010 05:25:55 -0800 (PST), Janis > > <janis_papanag...(a)hotmail.com> wrote: > >$ grep '[ \t]' <<< $'\v' | od -c > >0000000 > > >$ grep '[[:space:]]' <<< $'\v' | od -c > >0000000 \v \n > >0000002 > > Excellent examples but obscure for newbie like me to figure out its > meaning, especially the latter part of your codes: <<< $'\v' | od -c. The part CMD <<< STRING is similar to the ancient but often used echo STRING | CMD The $'\CHAR' is used to express control characters \CHAR, like \n for newline or \t for tab. So what I do is to feed a control character \v into the grep command. Why I do this is to show that \v is part of the [:space:] character class. Because the output of the grep command will contain a "non-printable" control code, the \v character, I use the od(1) command to make it visible. Janis > Any hints? > -- > .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
From: Janis on 16 Feb 2010 08:25 On 16 Feb., 14:13, Hongyi Zhao <hongyi.z...(a)gmail.com> wrote: > Hi all, > > What's the differences between [[:space:]] and [ \t ] when using both > in regex pattern? > -- > .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :. $ grep '[ \t]' <<< $'\v' | od -c 0000000 $ grep '[[:space:]]' <<< $'\v' | od -c 0000000 \v \n 0000002 IOW; [:space:] defines a character class that may contain more characters than explicitly listed in your character enumeration. Janis
From: Ed Morton on 16 Feb 2010 08:31 On 2/16/2010 7:13 AM, Hongyi Zhao wrote: > Hi all, > > What's the differences between [[:space:]] and [ \t ] when using both > in regex pattern? http://en.wikipedia.org/wiki/Regular_expression#POSIX_character_classes
From: Chris F.A. Johnson on 16 Feb 2010 11:47 On 2010-02-16, Janis wrote: > On 16 Feb., 15:15, Hongyi Zhao <hongyi.z...(a)gmail.com> wrote: >> On Tue, 16 Feb 2010 05:25:55 -0800 (PST), Janis >> >> <janis_papanag...(a)hotmail.com> wrote: >> >$ grep '[ \t]' <<< $'\v' | od -c >> >0000000 >> >> >$ grep '[[:space:]]' <<< $'\v' | od -c >> >0000000 ?\v ?\n >> >0000002 >> >> Excellent examples but obscure for newbie like me to figure out its >> meaning, especially the latter part of your codes: <<< $'\v' | od -c. > > The part > > CMD <<< STRING > > is similar to the ancient but often used > > echo STRING | CMD It's a non-portable equivalent of the standards-compliant here document: CMD <<EOF STRING EOF > The $'\CHAR' is used to express control characters \CHAR, like \n for > newline or \t for tab. But it's not standard. -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== ===== and is released under the GNU General Public Licence =====
|
Next
|
Last
Pages: 1 2 3 4 Prev: Use shell command to judge whether a file is in pdf format or not. Next: [[:space:]] and [ \t ]. |