I am trying to use cut to tell me the suffix of a file. for example: echo /home/silentm/log/file.machine.log | cut -d . -f 1-
I was expecting to get .log or log but I get the entire string echoed back.
doing the opposite gave me what I expected: echo /home/silentm/log/file.machine.log | cut -d . -f 1 gives me /home/silentm/log/file
I am trying to find a way to test if the file ends in .log?
How might I do that.
Thanks,
Jerry
On 09/02/2005 04:00 PM, Jerry Geis wrote:
I am trying to use cut to tell me the suffix of a file. for example: echo /home/silentm/log/file.machine.log | cut -d . -f 1-
I was expecting to get .log or log but I get the entire string echoed back.
doing the opposite gave me what I expected: echo /home/silentm/log/file.machine.log | cut -d . -f 1 gives me /home/silentm/log/file
I am trying to find a way to test if the file ends in .log?
How might I do that.
If you really want to >cut< .log you could use basename /home/silentm/log/file.machine.log .log.
Best, Oliver
Jerry Geis wrote:
I am trying to use cut to tell me the suffix of a file. for example: echo /home/silentm/log/file.machine.log | cut -d . -f 1-
I was expecting to get .log or log but I get the entire string echoed back.
doing the opposite gave me what I expected: echo /home/silentm/log/file.machine.log | cut -d . -f 1 gives me /home/silentm/log/file
I am trying to find a way to test if the file ends in .log?
Awk will do it: # echo /home/silentm/log/file.machine.log | awk -F. '{print $NF}' log
The benefit of awk is that you don't have to know how many dots are in the file. $NF just prints the last one.
-Mark
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Fri, Sep 02, 2005 at 09:00:22AM -0500, Jerry Geis wrote:
I am trying to use cut to tell me the suffix of a file. for example: echo /home/silentm/log/file.machine.log | cut -d . -f 1-
I was expecting to get .log or log but I get the entire string echoed back.
doing the opposite gave me what I expected: echo /home/silentm/log/file.machine.log | cut -d . -f 1 gives me /home/silentm/log/file
echo /home/silentm/log/file.machine.log | sed 's/^.*.([^.]*)$/\1/'
Will work all the time.
/home/silentm/log/file.machine.log --> log /home/silentm/log/file.machine.log.1.2.3.4 --> 4
If you want to get the dot too, just use 's/^.*(.[^.]*)$/\1/' instead.
Best Regards,
- -- Rodrigo Barbosa rodrigob@suespammers.org "Quid quid Latine dictum sit, altum viditur" "Be excellent to each other ..." - Bill & Ted (Wyld Stallyns)
On Friday 02 September 2005 15:00, Jerry Geis wrote:
I am trying to use cut to tell me the suffix of a file. for example: echo /home/silentm/log/file.machine.log | cut -d . -f 1-
Bad to use but it would be 3-, not 1-
I was expecting to get .log or log but I get the entire string echoed back.
doing the opposite gave me what I expected: echo /home/silentm/log/file.machine.log | cut -d . -f 1 gives me /home/silentm/log/file
I am trying to find a way to test if the file ends in .log?
How might I do that.
Thanks,
Jerry
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos