Extract directory name from the full directory path in UNIX using shell scripting
My input is as below :
From the above input I want to extract the file names only .
Basically I want to extract anything after 4th slash (/) , as the file will always be under third directory .
Last edited by IshuGupta; 06-03-2014 at 07:01 PM..
I have a text file with full list of files with their full path. I wanted to sort it by directory then files then subdirectory by alphabetically. When I used the sort command it doesn't give like what I want. Could somebody help me on this.
Here is the ex:
This is what I'm getting... (2 Replies)
Hi,
I have a file abcd.txt which has contents in the form of full path file names i.e.
$home> vi abcd.txt
/a/b/c/r1.txt
/q/w/e/r2.txt
/z/x/c/r3.txt
Now I want to retrieve only the directory path name for each row
i.e
/a/b/c/
/q/w/e/
How to get the same through shell script?... (7 Replies)
Hi,
Is there a command that tells you right away the current working directory? I know the command "pwd", but that one gives the full path.
if pwd gives me:
/a/b/c/d/ggg/HERE
I want something that will give me:
HERE
Thanks,
Gaurab (13 Replies)
Hey
I'm new to the forums here, and I'm seeking help for this script that I'm writing. When I do ls -l of a directory it shows the full pathname for files in it. For example, if the directory is /internet/post/forum/ and the file is topic, it currently shows internet/post/forum/topic. What's the... (3 Replies)
I'm running AIX unix korn shell. If I echo $0, I only get the filename, it does not have the directory name also. So when I do: `dirname $0` it returns a . (meaning current directory). How get $0 to return the full path/filename? Do I need something in my .profile? Thank you. (8 Replies)
I think I know what this is doing, but the 'eval' is confusing
fname=$(echo ${lineItem} | awk 'BEGIN {FS=";"}{print $1}')
fname=${fname%%+(])}
fname=${fname##+(])}
eval "fname=${fname}"
The first line extracts the contents of the line preceeding the ";"
2nd & 3rd lines trim the value (I... (5 Replies)
I need a script which should watch a directory for a file with specific directory.
If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column.
The file should be moved to another directory and the a... (8 Replies)
i was attempting to extract a directory path that was passed from a parameter with this code
vdir=`dirname $p1`
echo current directory $vdir
it does not work when the parameter passed has wild card on it.
for example
$ sh sample1.sh "/sbin/log/c*.log"
dirname: extra operand... (2 Replies)