Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Bash script - Remove the 3 top level of a full path filename Post 302986613 by jcdole on Monday 28th of November 2016 09:39:39 AM
Old 11-28-2016
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 something like :
Code:
SRC="/a/b/c/d/e"
DEST="/d/e"

   cp_function --parents "$SRC"   "$DEST"

Any help is welcome.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Full path of executing script in ksh?

Hello all, Here's the scenario: I've got a script, let's call it script1. This script invokes another script, which we'll call set_env, via the dot "." command, like so: File: #!/bin/ksh # region_id=DEV . set_env ${region_id} and so on. Script set_env sets up an... (2 Replies)
Discussion started by: BriceBu
2 Replies

2. 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

3. Shell Programming and Scripting

Maintain full path of a script in a var when sourcing it from a different script

Hi All, I've searched through the forum for a solution to this problem, but I haven't found anything. I have 2 script files that are in different directories. My first script, let's call it "/one/two/a.sh" looks like this: #!/bin/sh IN_DIR=`dirname $0` CUR_DIR=`pwd` cd $IN_DIR... (4 Replies)
Discussion started by: mrbluegreen
4 Replies

4. Shell Programming and Scripting

Help needed removing two top level folders from path

Hi, I am trying to use either awk or sed to drop the first two folders in a path. So if I had path /folder1/folder2/folder3/folder4.... I need to drop folder1&2, so the new path would be /folder3/folder4... If folder1 and folder2 were the same all the time, this would be easy. But... (4 Replies)
Discussion started by: robertinohio
4 Replies

5. Shell Programming and Scripting

Replace a filename with full path using sed

hi, i need to replace a line a file with a new raw device location.. original file.. /opt/sybase/ASE1502/ASE-15_0/bin/dataserver \ -d/data/TST_AKS1/sybdevices/master.dat \ -e/logs/sybase/TST_AKS1/SFO_TST_AKS1.log \ -c/apps/sybase/ASE1502/ASE-15_0/TST_AKS1.cfg \... (2 Replies)
Discussion started by: aksaravanan
2 Replies

6. Shell Programming and Scripting

[BASH] Remove Link from Filename

Hi there, I'm trying to make a script that downloads something, but then strips the URL for later processing. A user would input the following: ./text -install <link> Lets say the <link> is: Later on, the script would have to; unpack the file with the command: tar xvf... (6 Replies)
Discussion started by: Syekiya
6 Replies

7. 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

8. Shell Programming and Scripting

How to extract strings from full path when full path is not fixed

/Path/snowbird9/nrfCompMgrRave1230100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird6/nrfCompMgrRave1220100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird14/nrfCompMgrRave920100920.log.gz:09/20/2010 06:14:51 ERROR Error Message.... (0 Replies)
Discussion started by: Shirisha
0 Replies

9. 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

10. Shell Programming and Scripting

Please help I want script to check filename, size and date in specify path.

Please help, I want script to check filename, size and date in specify path. I want output as: DATE: YYYYMMDD HH:MM ------------------------------------------------ fileA,filesize,yyyy mm dd HH:MM fileA,filesize,yyyy mm dd HH:MM fileA,filesize,yyyy mm dd HH:MM fileA,filesize,yyyy mm dd... (1 Reply)
Discussion started by: akeji
1 Replies
ns_file(3aolserver)					    AOLserver Built-In Commands 				       ns_file(3aolserver)

__________________________________________________________________________________________________________________________________________________

NAME
ns_chmod, ns_cp, ns_cpfp, ns_ftruncate, ns_link, ns_mkdir, ns_rename, ns_rmdir, ns_symlink, ns_truncate, ns_unlink - File manipulation com- mands SYNOPSIS
ns_chmod option ?arg arg ...? ns_cp option ?arg arg ...? ns_cpfp option ?arg arg ...? ns_ftruncate option ?arg arg ...? ns_link option ?arg arg ...? ns_mkdir option ?arg arg ...? ns_rename option ?arg arg ...? ns_rmdir option ?arg arg ...? ns_symlink option ?arg arg ...? ns_truncate option ?arg arg ...? ns_unlink option ?arg arg ...? _________________________________________________________________ DESCRIPTION
ns_chmod filename mode Change a file's access permissions. ns_chmod changes the specified file's permissions to mode, in the same manner as the Unix chmod(1) command-line utility. ns_cp -preserve file1 file2 Copy one file to another. ns_cp copies the contents of file1 to file2, just like the Unix "cp" command. The default directory is the home directory for the server. If -preserve is specified, the copied file will retain the creation time, modification time, owner, and mode of the original file, just like the Unix "cp -p" command. ns_cpfp fileid1 fileid2 ?nbytes? Copy a specified number of bytes from one file to another. ns_cpfp copies information from one file (fileid1) to another (fileid2). If you specify a number of bytes in the nbytes argument, only the specified number of bytes will be copied. By default, the entire file is copied. ns_ftruncate fileid ?length? Truncate an open file to a specified length. ns_ftruncate causes the open file specified by fileid to have a size of length bytes. If length is not specified, it causes the file to have a size of zero bytes. The file must be open and be a regular file. ns_link ?-nocomplain? filename1 filename2 Create a link. ns_link creates a link named filename2 that points to the file specified by filename1. If the link fails, a Tcl error is generated, unless -nocomplain is specified. ns_mkdir path Create a directory. ns_mkdir creates the directory named PATH, just like the Unix mkdir command. By default, under Unix the direc- tory is created with the file permissions set to 0755 (rwxr-xr-x.). These permissions can be modified by setting the umask parameter for the server. ns_rename file1 file2 Rename a file. ns_rename renames the first file (file1) to the file name specified by file2. Make sure that the files and the directories in which the files exist are read/write accessible to the username that's running the AOLserver. ns_rmdir path Remove a directory. ns_rmdir removes the directory named path, just like the Unix rmdir command. The directory must already be empty. ns_unlink [-nocomplain] filename Remove a file. ns_unlink attempts to remove the file filename. If -nocomplain is not passed in and the removal fails, a Tcl error is generated. ns_truncate filename ?length? Truncate a file to a specified length. ns_truncate causes the file specified by filename to have a size of length bytes. If length is not specified, it causes filename to have a size of zero bytes. The file must exist and be a regular file. ns_unlink [-nocomplain] filename Remove a file. ns_unlink attempts to remove the file filename. If -nocomplain is not passed in and the removal fails, a Tcl error is generated. SEE ALSO
ns_chmod, ns_cp, ns_cpfp, ns_ftruncate, ns_link, ns_mkdir, ns_rename, ns_rmdir, ns_symlink, ns_truncate, ns_unlink KEYWORDS
AOLserver 4.0 ns_file(3aolserver)
All times are GMT -4. The time now is 07:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy