basename(1) General Commands Manual basename(1)Name
basename - strip directory names from pathname
Syntax
basename string [ suffix ]
Description
The command deletes from string any prefix up to and including the last slash (/) and the suffix (if specified), and prints the result on
the standard output. The command handles limited regular expressions in the same manner as metacharacters must be escaped if they are
intended to be interpreted literally. For example:
% basename /vmunix .x
vmun
% basename /vmunix '.x'
vmunix
In the first example, returns because it interprets the as a regular expression consisting of any character followed by the letter In the
second example, the dot is escaped; there is no match on a dot followed by and returns
The command is often used inside substitution marks (` `) within shell procedures.
Examples
The following example shell script compiles the file and moves the output to in the current directory:
cc /usr/src/bin/cat.c
mv a.out `basename $1 .c`
The following example echoes only the base name of the file by removing the prefix and any possible sequence of characters following the
period in the file's name:
% basename /etc/syslog.conf '..*'
syslog
See Alsodirname(1), ex(1), sh(1)basename(1)
Check Out this Related Man Page
basename(1B) SunOS/BSD Compatibility Package Commands basename(1B)NAME
basename - display portions of pathnames
SYNOPSIS
/usr/ucb/basename string [suffix]
DESCRIPTION
The basename utility deletes any prefix ending in `/' and the suffix, if present in string. It directs the result to the standard output,
and is normally used inside substitution marks (` `) within shell procedures. The suffix is a string with no special significance attached
to any of the characters it contains.
EXAMPLES
Example 1: Using the basename command.
This shell procedure invoked with the argument /usr/src/bin/cat.c compiles the named file and moves the output to cat in the current direc-
tory:
example% cc $1
example% mv a.out `basename $1 .c`
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWscpu |
+-----------------------------+-----------------------------+
SEE ALSO sh(1), attributes(5)SunOS 5.10 28 Mar 1995 basename(1B)
I have a script which has several occurences of statement like
command: $UCMDPATH/xyz abc
I would like to replace the entire line starting from $UCMDPATH with the ls -ltr command
eg:
Prior to change::
command: $UCMDPATH/xyz abc
After change:
command: ls -ltr
Is there a way to do... (12 Replies)
I have two sripts running in bash. The first one uncompresses log files and moves them to a working directory using uncompress -c and > output to new directory. It then creates one control record to assure our search returns a record. It then calls or executes the second script, which is a grep for... (6 Replies)
Hi guys if i do
a=`basename -e -s /home/j/john/*`
du -k -h $a | sort -nr | head -10
why when i run the script does it work but also say usage basename string
any ideas thanks (9 Replies)
hi if we have to use basename how can we do this in awk?
did the below but is not working..
psg -t "?"| awk '{
command=($5 ~ /^/)? $9:$8
# cmd_name=`basename $command` (gives error)
system("basename $command >>... (10 Replies)
Hi
Can somebody please help me know how do i match the basename using a regular expression using posix standard in shell script
suppose i want to match
/u01/Sybase/data/master.dbf the result should be master.dbf as i want to match everything after the last /
regards (8 Replies)
I have a long string that looks something like this....
<string>http://abc.com/40/20/zzz061-3472/dP3rXLpPPV2KC846nJ4VXpH7jt4b3LJgkL/tarfile_date.tar</string>
I need to but the tar file name. So I need to put between "/" and ".tar</string>". My desired result should be "tarfile_date". (7 Replies)
Hi Experts,
I have a syslog file from 1000's of different hosts which I want to adjust by removing the domain suffix from the hosts.
My previous attempts haven't managed to match all the different lenghts of the subdomains which are being logged.
Could somebody suggest which sed syntax... (6 Replies)
Hi,
I would like to extract a substring from a string in unix.
eg:
./checkfile.sh -- i need only checkfile.sh from this string.
Could someone help me out in this...
Regards
Arun (19 Replies)
Hello Friends,
I have written a code on a Linux box, however, am getting issues while running it on a Solaris server. The issue with Sed command is sortd out, however, am still lokking for solutions with expr command. Here is the issue,
Linux :
bash-2.03$ expr match singh@test.com... (10 Replies)
I need to parse log files using nawk, but I'm not able to pass script input argument (date) to nawk, for example:
------------
#!/bin/ksh
read date
nawk -F, '{if($1==date) print $4" "$5}'
-------------
Is there a way to pass an argument to nawk from shell script.
Many thanks... (8 Replies)
im trying to extract the basename of a process running on a host
processx is running at host1 as /applications/myapps/bin/processx
i wanted to check if its running, then extract the basename only using:
$ ssh host1 "ps aux | grep -v 'grep' | grep 'processx'" | awk '{ print basename $11}'
... (10 Replies)
can some one please tell me what is the problem with my syntax:confused:
I have 100 files in one folder
1. want to read each of the line by line
2. calculate their number of the words between the first word and the last word of each line
3. create file for each file with number of words... (8 Replies)
Hi ! all
I have need of accessing multiple files of different type same base name, and I want to compare base name if matching then I want to send those 2 files of different type to some program, for further processing
my files are like this
file_1.txt
file_2.txt
file_3.txt
file_4.txt... (6 Replies)
I want to extract the filename from a string.
This is how I have the rawdata ina file
/home/sid/ftp/testing/abc.txt
/home/sid/ftp/tested/testing/def.txt
/home/sid/sftp/date/misc/hij.txt
i want a script which would provide me an output like this
Directory ... (10 Replies)