how to remove the path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to remove the path
# 1  
Old 01-05-2011
how to remove the path

Hi,
I have a variable i; I want variable j to be derived from variable i

for ex:
i=/home/mbsprod/agency/hyb_agg_file.pl
then j should be
j=hyb_agg_file.pl

how to do this ?

Thanks,
Ram.
# 2  
Old 01-05-2011
Code:
j="`perl /home/mbsprod/agency/hyb_agg_file.pl`"

# 3  
Old 01-05-2011
Code:
i=/home/mbsprod/agency/hyb_agg_file.pl

j=${i##*/}

# 4  
Old 01-05-2011
Code:
i=/home/mbsprod/agency/hyb_agg_file.pl

j=`basename $i`

# 5  
Old 01-05-2011
I have a page full of scripts; the scripts are in various folders; I want to copy each script to a destination folder:

here is my script:
Code:
for i in `cat filename`
do
cp $i $destfold/$j
done

Example of my filename:
Code:
/home/mbsprod/bin/pool_update_fac_dat.pl
/home/mbsprod/bin/update_knob_file.pl
/home/MtgMdlApps/hybidx/bin/create_ramp_file.pl
/home/MtgMdlApps/hybidx/bin/patch_rtn_univ.pl
/home/MtgMdlApps/POOLS/InfoAtOrigDate/bin/bd_date_check.pl

I want my output to be :
Code:
$destfold/pool_update_fac_dat.pl
$destfold/update_knob_file.pl
$destfold/create_ramp_file.pl
$destfold/patch_rtn_univ.pl
$destfold/bd_date_check.pl

Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples, thank you.

Last edited by Franklin52; 01-05-2011 at 03:31 PM..
# 6  
Old 01-05-2011
Code:
while read i
do
  j=${i##*/}  
  cp $i $destfold/$j
done < filename

# 7  
Old 01-05-2011
Code:
echo $i | awk -F'/' '{print $NF}'

will show the last field

Code:
j=`echo $i | awk -F'/' '{print $NF}'`

will store last field to variable j
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

2. UNIX for Beginners Questions & Answers

Bash script - Remove the 3 top level of a full path filename

Hello. Source file are in : /a/b/c/d/e/f/g/some_file Destination is : /d/e where sub-directories "f" and "g" may missing or not. After copying I want /a/b/c/d/e/f/g/file1 in /d/e/f/g/file1 On source /a is top-level directory On destination /d is top-level directory I would like... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

Moving files from parent path to multiple child path using bash in efficient way

Hi All, Can you please provide some pointers to move files from Base path to multiple paths in efficient way.Folder Structure is already created. /Path/AdminUser/User1/1111/Reports/aaa.txt to /Path/User1/1111/Reports/aaa.txt /Path/AdminUser/User1/2222/Reports/bbb.txt to... (6 Replies)
Discussion started by: karthikgv417
6 Replies

4. Shell Programming and Scripting

Function to remove the directories from PATH variable

Hello, From the URL https://www.unix.com/shell-programming-scripting/121303-remove-path-path-environment-variable-2.html I got a function to remove the directories from a path. but looks like this isnt quite working.. i am also not able to post the comments in the thread as it is closed. ... (6 Replies)
Discussion started by: satishkumar432
6 Replies

5. Shell Programming and Scripting

How to remove a directory path in a file using sed

Hi, I want to remove a directory path from a file starting with the bracket using sed command. eg. (cd /man/abc/def ; \ aaaaa bbbb (cd /man/aaaa/aa; \ op. aaaaa bbbb The "(cd /man" is to be consideres as the start. I tries the below thing, but it didnt worked. Can anyone help.... (3 Replies)
Discussion started by: vdhingra123
3 Replies

6. AIX

How to remove the entry for the path in aix

Hi The below command shows as root@cbspsdb02 #export MQSI_USER_EXIT_PATH64=/opt/IBM/ITM/aix513/d4/KD4/config/wmb61/lib root@cbspsdb02 #print $MQSI_USER_EXIT_PATH64 /opt/IBM/ITM/aix513/d4/KD4/config/wmb61/lib I need to remove the entry for the path "$MQSI_USER_EXIT_PATH64". That is... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

7. Shell Programming and Scripting

How to remove filename from the path

Hi, I have a list of paths with files at the end. How can strip off filenames. This is what I have: /apps/test/abc/file.txt /apps/new/home/daily/report.xml /apps/old/home/weekly/out/test.sh This is what I need: /apps/test/abc/ /apps/new/home/daily/ /apps/old/home/weekly/out/ ... (10 Replies)
Discussion started by: djanu
10 Replies

8. Shell Programming and Scripting

remove a path from PATH environment variable

Hi I need a script which will remove a path from PATH environment variable. For example $echo PATH /usr/local/bin:/usr/bin:test/rmve:/usr/games $echo rmv test/rmve Here I need a shell script which will remove rmv path (test/rmve) from PATH... (9 Replies)
Discussion started by: madhu84
9 Replies

9. Shell Programming and Scripting

how to remove "../.. from a path"

My input path can be either somepath (/tmp/life ) or ../../somepath ( ../../tmp/life ) Can someone help me help me with script to always extract "somepath" on both inputs Thanks in advance (8 Replies)
Discussion started by: vickylife
8 Replies

10. UNIX for Dummies Questions & Answers

Remove path from filename

In a foreach loop I end up with $file containing the filename INCLUDING the whole path. I want this reduced to just the filename, but I can't seem to remember how I did it some years back. I am sure I can do it with "sed", but I am pretty sure I have seen a simpler command. Anyone? borgeh (3 Replies)
Discussion started by: borgeh
3 Replies
Login or Register to Ask a Question