How to parse a pathname in csh?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to parse a pathname in csh?
# 1  
Old 07-18-2008
How to parse a pathname in csh?

I am wondering if there's an easy way to extract individual directories from a pathname in a csh script. For example, if I have a shell variable such as
set datadirlist = /space/quimby/1

can I get 'space', 'quimby', and '1' and assign it individually to another variable?

Any suggestions would be greatly appreciated.

Sam


# 2  
Old 07-18-2008
Quote:
Originally Posted by same1290
I am wondering if there's an easy way to extract individual directories from a pathname in a csh script. For example, if I have a shell variable such as
set datadirlist = /space/quimby/1

can I get 'space', 'quimby', and '1' and assign it individually to another variable?

Any suggestions would be greatly appreciated.

Sam


Try this: set datadirlist = /space/quimby/1; echo $datadirlist | awk -F/ '{print $2"\n" $3"\n" $4"\n"}'.
# 3  
Old 07-21-2008
How to parse a pathname in csh?

Thank you very much. That works perfectly, exactly what I need. (I should learn awk one of these days.)

>> Originally Posted by same1290 View Post
>> I am wondering if there's an easy way to extract individual directories from >> a pathname in a csh script. For example, if I have a shell variable such as
>> set datadirlist = /space/quimby/1
>>
>> can I get 'space', 'quimby', and '1' and assign it individually to another variable?
>>
>> Any suggestions would be greatly appreciated.
>>
>> Sam


> Try this: set datadirlist = /space/quimby/1; echo $datadirlist | awk -F/ '{print $2"\n" $3"\n" $4"\n"}'.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rename files with its pathname

Hi, I have a few csv files within the directory structure as shown below /tmp/user/Proj/V1/data/Common1/Zip1/123.csv /tmp/user/Proj/V1/data/Common2/Zip2/3453.csv /tmp/user/Proj/V1/data/Common2/Zip2/1234.csv and so on... I need to get these csv files and move to another dir... (5 Replies)
Discussion started by: Jag02
5 Replies

2. Shell Programming and Scripting

Command to get the pathname in variable

Hi, I want to saperate file path and file name into two variables. for ex:- lets say file is /home/prasoon/File.txt i want FILE_PATH=/home/prasoon and FILENAME=File.txt i need your help. Cheers Prasoon (2 Replies)
Discussion started by: prasson_ibm
2 Replies

3. UNIX for Dummies Questions & Answers

Why Do You Need the Explicit Pathname to Execute?

Hi! If your working directory contains a file you want to work on, or give as an argument, you don't have to give the explicit pathname, just the filename, like so: $ vi while_loop.ksh But if you want execute an executable file, you must supply the explicate pathname, like so: ./while_loop.ksh... (20 Replies)
Discussion started by: sudon't
20 Replies

4. Shell Programming and Scripting

SED - Pathname problem

Hello. After looking through the forum I am trying without success to remove lines from a file each time that ligne contains a pattern. As this is running in script, I am using some variables: The command : sed '/pattern/d' source_file > corrected_source_file In the script sed ... (2 Replies)
Discussion started by: jcdole
2 Replies

5. Shell Programming and Scripting

Trim pathname of the file

I am capturing the files in a directory to an array. I have 2 arrays with list of files in two different directories. Both the directories are supposed to have the same number of files and filenames. I want to check that the same file exists in both the directories. After I capture the... (1 Reply)
Discussion started by: Sangtha
1 Replies

6. UNIX for Dummies Questions & Answers

finding pathname for directory

Hi Could someone help me? I'm not sure how to find the full pathname of a directory. I just want to be able to specify a directory. e.g directory1/directory2/directory3/directory4/directory5 I want to be able to put in "directory5" and then i want a return of the full address. ... (3 Replies)
Discussion started by: shomila_a
3 Replies

7. Shell Programming and Scripting

eliminate pathname from the file name in the o/p

Hi, Im finding some files form a specific path and den writing those files to another file as: find /SYS/admin/data/xml -name '*.xml' -type f ! -newer file1 -print >>out.xml and when im doing cat out.xml im getting like dis: ... (2 Replies)
Discussion started by: ss_ss
2 Replies

8. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

9. Shell Programming and Scripting

Getting pathname variables with ksh

With C Shell you can get the root, head, tail and extension of a pathname by using pathname variable modifiers. Example Script: #! /bin/csh set pathvar=/home/WSJ091305.txt echo $pathvar:r echo $pathvar:h echo $pathvar:t echo $pathvar:e The result of executing this script is: ... (7 Replies)
Discussion started by: BCarlson
7 Replies

10. UNIX for Dummies Questions & Answers

find without pathname

How can I get the results of a find back without the pathname for example if i do find ../../ -name \*.sql i dont want to see directory/directory/filename.sql I only want to see filename.sql (3 Replies)
Discussion started by: MBGPS
3 Replies
Login or Register to Ask a Question