How to get complete path in variable excluding last word?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to get complete path in variable excluding last word?
# 1  
Old 07-14-2011
How to get complete path in variable excluding last word?

Hello Experts,

Can you please help me by providing a code which can give me the complete path except last word in a variable, the variable i can use anywhere else for my operation

eg:

if this below one is my path:

user/oracle/Test_admin/myfolder/bakup/part_bkptemp_part_bkp_repeated/list.txt

I want a code which can pull

user/oracle/Test_admin/myfolder/bakup/part_bkptemp_part_bkp_repeated/

in a variable excluding "list.txt" [last word.]

Please helpSmilie

Last edited by aks_1902; 07-14-2011 at 04:49 AM..
# 2  
Old 07-14-2011

dirname


Code:
 
$ dirname "a/b/c.txt"
a/b

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 07-14-2011
Code:
$> VAR=user/oracle/Test_admin/myfolder/bakup/part_bkptemp_part_bkp_repeated/list.txt
$> echo ${VAR%/*}"/"
user/oracle/Test_admin/myfolder/bakup/part_bkptemp_part_bkp_repeated/

or
Code:
$> V=$(dirname user/oracle/Test_admin/myfolder/bakup/part_bkptemp_part_bkp_repeated/list.txt)`echo '/'`
$> echo $V
user/oracle/Test_admin/myfolder/bakup/part_bkptemp_part_bkp_repeated/

or
Code:
$> BLA=user/oracle/Test_admin/myfolder/bakup/part_bkptemp_part_bkp_repeated/list.txt
$> echo $BLA| sed 's/[^/]*$//'
user/oracle/Test_admin/myfolder/bakup/part_bkptemp_part_bkp_repeated/

This User Gave Thanks to zaxxon For This Post:
# 4  
Old 07-14-2011
thanks a lot

---------- Post updated at 02:56 AM ---------- Previous update was at 02:55 AM ----------

Awesome dude thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed in excluding certain word patterns

Hi, I need help with following. I need to exclude words that match following patterns a. more than length 4 (example SBRAP) b. contains mixture uppercase and lower case regardless of the length (example GSpD) File contains COFpC MCHX SP SNFCA GEH SBRAP DGICA JPMpE WFCpP GSpD AXL... (5 Replies)
Discussion started by: jakSun8
5 Replies

2. Programming

How can I read complete word from text file?

how can I know that the word in test file end at this point .... I have an Idea to search on ' ' , '\n' or '\0' but don't know what function can store the string before those characters .. help please ! (3 Replies)
Discussion started by: fwrlfo
3 Replies

3. Shell Programming and Scripting

Help needed in excluding word

Hello, When i run this command find ./ -type f -print | xargs grep -l 'myWord' it prints the file name where 'myWord' exists and also something like the below which i want to exclude grep: can't open Fields grep: can't open Search I tried piping and grep -v 'open' but it did not work. ... (3 Replies)
Discussion started by: jakSun8
3 Replies

4. Shell Programming and Scripting

extracting part of a line excluding particular word from it

here is the line on which i want to process `empNo` int(13) NOT NULL AUTO_INCREMENT, it sometimes doesnt have comma at the end too `empNo` int(13) NOT NULL AUTO_INCREMENT i want to extract all except "AUTO_INCREMENT" not only this line i ,want the code to work on any line if it has... (5 Replies)
Discussion started by: vivek d r
5 Replies

5. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

6. Shell Programming and Scripting

Word count while excluding

Hello, Is there a way to word count a file while excluding lines that have FRP in them? wc -l "filename"? Thanks in advance Gideon (4 Replies)
Discussion started by: blitzkreg6
4 Replies

7. UNIX for Dummies Questions & Answers

how to find complete path of a file in unix

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to capture... (5 Replies)
Discussion started by: yahoo!
5 Replies

8. UNIX for Advanced & Expert Users

how to find complete path of a file in unix

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to capture... (1 Reply)
Discussion started by: yahoo!
1 Replies

9. UNIX for Advanced & Expert Users

Delete a word and complete line

Hi Canone please provide me solution how can achieve the result below: File1.txt $ sweet appleŁ1 scotish green $ This is a test1 $ sweet mangoŁ2 asia yellow $ This is a test 2 $ sweet apple red (there is no pound symbol here) germany green (1 Reply)
Discussion started by: Aejaz
1 Replies

10. UNIX for Advanced & Expert Users

ls -R command but need complete path name on each line

Can anyone help me with the following: I need to traverse subdirectories to create a list of files with the pathname. For example, here's what I get with a simple ls -alR command: /MAIN/data/30007390 dte2>>ls -alR .: total 2 drwxrwx--- 4 ecfadmin staff 96 Oct 24 18:35 . ... (2 Replies)
Discussion started by: condor4-2
2 Replies
Login or Register to Ask a Question