nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

extract the path

This is a discussion on extract the path within the Shell scripting forums, part of the Development/Scripting category; After running find command for a file i get ./db_app/crm_ace_sync/billing_recovery/ace/cfg/tx_update_address.ctl but i want to store in a variable address starting ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-05-2009, 11:59 AM
Junior Member
User
 
Join Date: Apr 2009
OS: Debian
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
huntethan is on a distinguished road
Exclamation extract the path

After running find command for a file i get
./db_app/crm_ace_sync/billing_recovery/ace/cfg/tx_update_address.ctl

but i want to store in a variable address starting from crm_ace_sync i.e

path =/crm_ace_sync/billing_recovery/ace/cfg.

if i go inside db_app and run
for i in `cat ../filelist.txt`
do
path=`find . -name $i|awk -F"$i" '{print $1}'` ---($i is the loop variable
it will give me the answer but the files not necessarily be always inside db_app because under stage there are several other directories which may contain the files.

how to do it and i have to do it for a large number of files which i will keep in loop so tell me the method to extraxt that address in that particular manner.
Reply With Quote
  #2 (permalink)  
Old 11-05-2009, 01:28 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Is string "crm_ace_sync" constant i.e. present in all file names?
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 11-05-2009, 01:31 PM
Junior Member
User
 
Join Date: Apr 2009
OS: Debian
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
huntethan is on a distinguished road
Default

not necessarily...
Reply With Quote
  #4 (permalink)  
Old 11-05-2009, 11:04 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,709
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

I'm sorry but I don't get you.. may be you can provide more info...
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 19-05-2009, 04:07 AM
Member
User
 
Join Date: May 2009
OS: Mandriva
Posts: 78
Thanks: 0
Thanked 14 Times in 14 Posts
Rep Power: 2
cfajohnson has a spectacular aura about cfajohnson has a spectacular aura about
Default

Quote:
Originally Posted by huntethan View Post
After running find command for a file i get
./db_app/crm_ace_sync/billing_recovery/ace/cfg/tx_update_address.ctl

but i want to store in a variable address starting from crm_ace_sync i.e

path =/crm_ace_sync/billing_recovery/ace/cfg.

Code:
file=./db_app/crm_ace_sync/billing_recovery/ace/cfg/tx_update_address.ctl
temp=${file#*/*/}
path=${temp%/*}
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
shellScript tht to extract the interface name if their HWaddr starts with 00:0C pooppp Shell scripting 0 31-07-2008 05:03 PM
Change /tmp path on KDE as it is too small for KDE marccarter0 Ubuntu / Debian 2 26-05-2008 09:34 PM
Script to extract some part of files: satish1482 Shell scripting 0 13-03-2007 05:30 PM
how to extract zip files in linux Linux software 1 10-01-2006 11:30 PM
Script to extract a specific row of data ricc Shell scripting 1 15-11-2005 02:29 PM


All times are GMT +5.5. The time now is 01:06 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38