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
with /home/silentm/log/file.machine.log you would need to use echo /home/silentm/log/file.machine.log | cut -d . -f3 echo /home/silentm/log/file.machine.log | cut -d . -f1 *-> /home/silentm/log/file echo /home/silentm/log/file.machine.log | cut -d . -f2 *-> machine echo /home/silentm/log/file.machine.log | cut -d . -f3 *-> log HTH - Jeff>>> geisj at pagestation.com 9/2/2005 9:00 AM >>>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 _______________________________________________ CentOS mailing list CentOS at centos.org http://lists.centos.org/mailman/listinfo/centos
when I do the the cut -d "." -f 2- I get 2 fields. If my file was /home/silentm/log/file.machine.log I get machine.log not just "log" the suffix?? Jerry
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 -- Mark Belanger LTX Corporation
-----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/fileecho /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 at suespammers.org> "Quid quid Latine dictum sit, altum viditur" "Be excellent to each other ..." - Bill & Ted (Wyld Stallyns) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFDGJr2pdyWzQ5b5ckRAtooAKCMXfJIq55g1s8zWBL4uy7GMTBP0gCfeBQV yEAjliwB2JaXCcnZkEbVPQ8=6CP3 -----END PGP SIGNATURE-----
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 at centos.org > http://lists.centos.org/mailman/listinfo/centos-- John Allen, mailto:john.allen at dublinux.net MandrakeClub Silver Member. http://www.dublinux.net Site of the day: http://www.kde.ie/ Mandrakelinux release 10.2 (Cooker) for i586, kernel 2.6.11-6mdk 21:35:23 up 1:18, 3 users, load average: 0.02, 0.07, 0.02