LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help for basename (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-for-basename-4175597274/)

jrffrey 01-12-2017 03:38 AM

Need help for basename
 
I have tried to run this:

Lets say i have two files in the current folder:
file1.xyz
file2.xyz

Quote:

$find . -name "*.xyz" | xargs basename -s ".xyz"
i was hoping to get
Quote:

file1
file2
but this is the output i got
Quote:

basename: invalid option -- 's'
this is the version of basename i have
Quote:

$basename --help
Usage: basename NAME [SUFFIX]
or: basename OPTION
Print NAME with any leading directory components removed.
If specified, also remove a trailing SUFFIX.
--help display this help and exit
--version output version information and exit
Examples:
basename /usr/bin/sort Output "sort".
basename include/stdio.h .h Output "stdio".

Report basename bugs to bug-coreutils@gnu.org
GNU coreutils home page: http://www.gnu.org/software/coreutils/
General help using GNU software: http://www.gnu.org/gethelp/
For complete documentation, run: info coreutils 'basename invocation'
[khorseik@ntu03 output]$ basename --version
basename (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.

rtmistler 01-12-2017 06:30 AM

I have basename version 8.25 and your command works fine.

Possible that this is a bug, however also possible is something else is wrong, my FSF statement shows (C) 2016 versus 2010.

rknichols 01-12-2017 08:15 AM

The 8.4 version of basename does not support the "-s" option.

BW-userx 01-12-2017 08:27 AM

Code:

DESCRIPTION
      Print NAME with any leading directory components removed.  If
      specified, also remove a trailing SUFFIX.

      Mandatory arguments to long options are mandatory for short options
      too.

      -a, --multiple
              support multiple arguments and treat each as a NAME

      -s, --suffix=SUFFIX
              remove a trailing SUFFIX; implies -a
....
....

GNU coreutils 8.26              January 2017                      BASENAME(1)


TenTenths 01-12-2017 09:29 AM

What does this give you:
Code:

find . -name "*.xyz" -exec basename {} .xyz \;

grail 01-12-2017 01:39 PM

TenTenths example should work as your own output gave the exact same example:
Code:

basename include/stdio.h .h Output "stdio".

jrffrey 01-12-2017 09:50 PM

Quote:

Originally Posted by TenTenths (Post 5653843)
What does this give you:
Code:

find . -name "*.xyz" -exec basename {} .xyz \;

Yes, this one works as what i want. But the problem, i need to use xargs as part of my next step of work.
So i guess i would need to find a workaround with the -exec

Turbocapitalist 01-13-2017 02:20 AM

You can use find with xargs. Leave out the -exec clause and use -print0 instead. Then for xargs use -0 or --null.

Be sure to check the manual pages for both periodically so that they start to become familiar.

Code:

man find
man xargs

Edit: see also the manual page for basename and the -a option.

pan64 01-13-2017 03:53 AM

you may find this http://www.thegeekstuff.com/2013/12/xargs-examples/ useful (or you can find similar pages too)

nodir 01-13-2017 11:44 AM

Quote:

Originally Posted by Turbocapitalist (Post 5654227)
You can use find with xargs. Leave out the -exec clause and use -print0 instead. Then for xargs use -0 or --null.

Be sure to check the manual pages for both periodically so that they start to become familiar.

Code:

man find
man xargs

Edit: see also the manual page for basename and the -a option.

You can, but you shouldn't.
http://mywiki.wooledge.org/UsingFind...and_-exec_.2B-

Turbocapitalist 01-13-2017 11:47 AM

Quote:

Originally Posted by nodir (Post 5654418)

Right. Re-read post #8 where -print0 is mentioned for find and --null mentioned for xargs

nodir 01-13-2017 12:04 PM

Oh, i read that.
And truth to be told: i am not that much in the subject that i could advise or explain it at all.
My post was rather focused at the OP, so he knows that some folks have strong opinions against usage of xargs ( while, like said, i for one sure can't say much about it).

in short: it really was a side-note only.

John VV 01-13-2017 07:02 PM

jrffrey
why are you using a old operating system from 2010
courutils 8.4 is 7 years old
http://ftp.gnu.org/gnu/coreutils/?C=M;O=D

rknichols 01-13-2017 08:31 PM

Red Hat Enterprise Linux 6 is fully supported until November 30, 2020, and uses coreutils-8.4. A lot of people are using it.


All times are GMT -5. The time now is 08:13 AM.