Sponsored Content
Top Forums Shell Programming and Scripting How to get the directory name from a path using csh? Post 302609037 by ygemici on Monday 19th of March 2012 08:11:18 AM
Old 03-19-2012
Quote:
Originally Posted by vdhingra123
hi,
Can you explane me how this command is working?
echo $path | awk -F\/ '{print $(NF-2), $(NF-1)}'

How can i store them in two different variables?
NF is the mean "The Number of Fields" in the current input record.
check this..
Code:
# echo $pathx|awk -F"/" '{print NF}'
10
total fields count is 10

So while your FS --> '/'
your $2--> home
your $5--> bad_BAD
$NF = $10 --> work (last element)
Code:
# set pathx="/home/abs/cad/bad_BAD/vdhingra/testcases/ABC/924/work"
set b=`echo $pathx | awk -F\/ '{print $(NF-2)}'`  # 8.the element
set c=`echo $pathx | awk -F\/ '{print $(NF-1)}'`   # 9.the element
# echo $b $c
ABC 924

This User Gave Thanks to ygemici For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

current directory as part of the csh prompt

I would like my csh prompt to behave like the linux csh prompt setting done by linux command (set prompt="%n@%m %c]$ ") how do I do that? What I'm trying to do is that I would like to see what directory I'm in by looking at the prompt. I've figured out that %n is like $user, and %m is like... (3 Replies)
Discussion started by: jamesloh
3 Replies

2. Shell Programming and Scripting

Truncate directory path

Is it possibe to use sed for the following? I would like to truncate the output of a directory path if it's over 3 directory levels deep. For example: /dir1/dir2/dir3 -- NO change required but, /dir1/dir2/dir3/dir4 would output as ~/dir4 Thanks. (4 Replies)
Discussion started by: here2learn
4 Replies

3. UNIX for Dummies Questions & Answers

How to get directory name from its path?

If I the path to a directory, what command can I use to return the actual name of that directory. test=`pwd`/folder1 > $test folder1 I'd rather avoid anything with regular expressions. Any ideas? (1 Reply)
Discussion started by: ordano
1 Replies

4. Shell Programming and Scripting

Retrieve directory path from full file path through sh

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)
Discussion started by: royzlife
7 Replies

5. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

6. HP-UX

Adding Directories to PATH in HP-UX with csh

HI Guys, I am truing to add some directories to the productive HP-UX (like /usr/sbin) the problem is that i tried some methods like (export) and setenv but i failed. I add some logs output of the commands to provide you with more info . the user which I am trying to add this path is different... (5 Replies)
Discussion started by: barry1946
5 Replies

7. Shell Programming and Scripting

Keep last directory from path

Hello, I am looking for a command that will give me the last directory name from a path ex 1 : /dir1/dir/2/dir3/ output needed dir3 ex 2 : /dir1/dir/2/dir3/dir4/ output needed dir4 (1 Reply)
Discussion started by: Aswex
1 Replies

8. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

9. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

10. UNIX for Beginners Questions & Answers

What is the difference ../directory path and ./directory path in ksh?

What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies
REMINISCENCE(6) 						   REminiscence 						   REMINISCENCE(6)

NAME
reminiscence - a wrapper around rs with changed defaults SYNOPSIS
reminiscence reminiscence --datapath path reminiscence --savepath path reminiscence --levelnum num reminiscence --help DESCRITION
reminiscence is a tiny wrapper for /usr/games/rs, the REminiscence engine. It supports the same options as rs(6). The wrapper bails out if the data directory does not exist. It will also create the save game directory if needed. OPTIONS
--datapath path Use path for locating game data. Defaults to .reminiscence/data in user's home directory. reminiscence exits with an error if the directory does not exist. --savepath path Use path for game saves. Defaults to .reminiscence/save in user's home directory. The directory is created if needed. --levelnum num Start from level num. Default is 0. --help Display short usage info. SEE ALSO
rs(6) COPYRIGHT AND LICENSE
Copyright 2010, 2011 Damyan Ivanov dmn@debian.org Permission is granted to use this work, with or without modifications, provided that this notice is retained. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. REminiscence 0.1.9 2011-03-17 REMINISCENCE(6)
All times are GMT -4. The time now is 07:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy