[SOLVED] Regular Expression Anchor '$' Not Working In grep..

This forum is dedicated to advanced help and support :

Ask here your questions about advanced usage of Mageia. For example you may post here all your questions about network and automated installs, complex server configurations, kernel tuning, creating your own Mageia mirrors, and all tasks likely to be touchy even for skilled users.

[SOLVED] Regular Expression Anchor '$' Not Working In grep..

Postby gdawg » Jan 3rd, '12, 18:55

Hi,
When I run
Code: Select all
jane@localhost ~> grep -h '.zip' dirlist*.txt
gunzip*
gzip*
bunzip2@
bzip2*
bzip2recover*
funzip*
gpg-zip*
gunzip@
gzip@
hunzip*
hzip*
mzip@
unzip*
unzipsfx*

However, I get this when I run:jane@localhost ~> grep -h 'zip$' dirlist*.txt I get no output. When I use '^' as an anchor I get the expected results. Is there a program that I need to install to be able to use '$' as an anchor? All help will be appreciated.
jane@localhost ~> uname -a
Linux localhost 2.6.38.8-desktop586-8.mga #1 SMP Fri Nov 4 00:11:45 UTC 2011 i686 i686 i386 GNU/Linux
I'm running Dell Inspiron 530S Desktop with Win 7 and numerous Linux distributions installed on two drives.
gdawg
 
Posts: 19
Joined: Sep 25th, '11, 14:17

Re: Regular Expression Anchor '$' Not Working In grep comman

Postby doktor5000 » Jan 3rd, '12, 20:38

Well, from looking at the expression, zip$ matches "zip" at the end of a line, but in your case there's always a character behind the "zip", either * or @. So no match.

Would you mind to tell what you want to achieve in the first place, i.e. a bit more context information?
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18252
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Regular Expression Anchor '$' Not Working In grep comman

Postby gdawg » Jan 4th, '12, 16:07

Thank you for your reply doktor5000. The dirlist*.txt is constructed from a combination of /bin, /usr/bin, /sbin, and /usr/sbin. It is a representation of the following commands: ls /bin > dirlist-bin.txt; ls /usr/bin > dirlist-usr-bin.txt; ls /sbin > dirlist-sbin.txt; and ls /usr/sbin > dirlist-usr-sbin.txt. I'm studying The Linux Command Line and this is one of the exercises. As you have correctly pointed out, each "zip" is followed by a * or @ symbol. My question now becomes: why is that the case? A review of the various /bins' reveals that all files in those directories have trailing characters. Thank you for your assistance.
gdawg
 
Posts: 19
Joined: Sep 25th, '11, 14:17

Re: Regular Expression Anchor '$' Not Working In grep comman

Postby doktor5000 » Jan 4th, '12, 16:44

gdawg wrote:I'm studying The Linux Command Line and this is one of the exercises. As you have correctly pointed out, each "zip" is followed by a * or @ symbol. My question now becomes: why is that the case? A review of the various /bins' reveals that all files in those directories have trailing characters.

That depends on what options you supply to the ls command. An asterisk (*) symbolizes the executable permission, and an @ symbol symbolizes a symlink (short for symbolic link, also known as softlink) Just look at the manpage of the ls command, via man ls. The option -F is responsible for that behaviour, and there's a default alias for the ls command, see:
Code: Select all
[doktor5000@mageia1 ~]$ alias ls
alias ls='ls -F --color=auto'


So if you don't want that -F option you either need to unalias the ls command or call it with the full path:
Just compare the output of
/bin/ls /bin
and
ls /bin
If you need further explanations just say so :)
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18252
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Regular Expression Anchor '$' Not Working In grep comman

Postby gdawg » Jan 4th, '12, 20:46

Thank you doktor5000 for that excellent explanation. Where are the aliases set and how can I edit them? I looked in '.bashrc' and that alias wasn't listed and 'man ls' returns 'no manual entry for ls'.
gdawg
 
Posts: 19
Joined: Sep 25th, '11, 14:17

Re: Regular Expression Anchor '$' Not Working In grep comman

Postby alf » Jan 4th, '12, 21:01

gdawg wrote: Where are the aliases set and how can I edit them?

aliases are defined in /etc/profile.d/xxalias.sh(where xx is a two digit number), don't know which it is in mageia exactly as I'm currently not in front of a mageia PC.
To list them all type 'alias' in console.

Oh, and before I forget to say, it's not a good idea to edit systemwide aliases as they could be overwritten by an update. Your own aliases will be stored in ~\.alias and used then instead of system aliases.
for windows problems reboot; for linux problems be root
alf
 
Posts: 326
Joined: Apr 1st, '11, 23:07
Location: DE Paderborn

Re: Regular Expression Anchor '$' Not Working In grep comman

Postby doktor5000 » Jan 4th, '12, 22:48

alf wrote:Oh, and before I forget to say, it's not a good idea to edit systemwide aliases as they could be overwritten by an update. Your own aliases will be stored in ~\.alias and used then instead of system aliases.

Actually you can also define them in ~/.bashrc, or anything that is source'd when you open up a shell :)
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18252
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Regular Expression Anchor '$' Not Working In grep comman

Postby gdawg » Jan 5th, '12, 00:00

Thank you very much alf and doktor5000. I found some aliases in /etc/profile.d/60alias.sh. I chose to leave those as-is and edited .bashrc to add alias ls='ls --color=auto. Thanks again for your excellent assistance.

Please mark this subject as solved. I can't seem to get it done.
gdawg
 
Posts: 19
Joined: Sep 25th, '11, 14:17

Re: [SOLVED] Regular Expression Anchor '$' Not Working In gr

Postby critter » Jan 7th, '12, 13:02

It is not necessary to permanently change an alias. If you want to execute the command bypassing the alias simply precede it with a backslash.
\ls instead of ls.

hth
critter
critter
 
Posts: 2
Joined: Jan 7th, '12, 12:57

Re: [SOLVED] Regular Expression Anchor '$' Not Working In gr

Postby gdawg » Jan 7th, '12, 20:43

Thank you critter for your help. I wasn't aware of that.
gdawg
 
Posts: 19
Joined: Sep 25th, '11, 14:17

Re: [SOLVED] Regular Expression Anchor '$' Not Working In gr

Postby ahtisham454 » Feb 8th, '12, 13:57

Very informational and educational as usual!
ahtisham454
 
Posts: 1
Joined: Feb 8th, '12, 13:54


Return to Advanced support

Who is online

Users browsing this forum: No registered users and 1 guest

cron