Sponsored Content
Top Forums Shell Programming and Scripting splitting up of absolute filepath Post 302102268 by aigles on Tuesday 9th of January 2007 09:52:26 AM
Old 01-09-2007
A solution :
Code:
full_path=/cas/43fg/temp/sample.txt
file=$(basename $full_path)
dir=$(dirname $full_path)

Jean-Pierre.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Length of a Unix filepath max length

Hi Guys, Could anyone shed some light on the length of a Unix filepath max length pls ? thanks ! Wilson (3 Replies)
Discussion started by: wilsontan
3 Replies

2. Shell Programming and Scripting

Absolute value

Is there a function in awk to get the absolute value of a-b which can be negative or positive, I just care for the absolute value... (5 Replies)
Discussion started by: placroix1
5 Replies

3. Shell Programming and Scripting

tar: extract single file to different filepath

Hi, This is my first post here - I'm hoping I can get some help! I have searched these forums and othersand not getting anything that works. I am trying to extract a single file from a tar archive to a diffierent location than it will default to. For example my tar log shows me ... a... (3 Replies)
Discussion started by: littleIdiot
3 Replies

4. UNIX for Dummies Questions & Answers

absolute value

is there any function in unix which will convert a integer to absolute value with a single decimal point. suppose x=15232 y=x/1024=14.875 i want y to be 14.8 Similarly if y=6.29452 it should come as 6.3 (3 Replies)
Discussion started by: dr46014
3 Replies

5. Shell Programming and Scripting

Grab a number at end of filepath

Hello, I have a file path such as: /path/to/whatever/30 and I want to get the number off the end. My problem is that there might be other numbers in the path and the last number can be 1 or 2 digits. I tried something like: sed 's/.*\(\/\{1,2\}\).*/\1/' which seems to work fine for single digit... (7 Replies)
Discussion started by: phreezr
7 Replies

6. Shell Programming and Scripting

Problem while using grep (multi-level) with the space-separated filepath.

Hi, I've been trying to use grep to find out all the files which have two particular patterns in it (both pattern1 AND pattern2). I have a script to do the same, in which I'm getting the output of the first grep (with -l option) which contains the list of file paths and I'm trying to search for... (3 Replies)
Discussion started by: NanJ
3 Replies

7. Solaris

How to get the filepath and filenames in pfiles PID command?

Hi, When I use pfiles PID, it displays the below output and i just see the inode, can i able to get the full path and file name? pl help me on this. Current rlimit: 8192 file descriptors 0: S_IFCHR mode:0620 dev:308,0 ino:12582968 uid:1001378434 gid:7 rdev:24,26 O_RDWR ... (3 Replies)
Discussion started by: balamv
3 Replies

8. Shell Programming and Scripting

How to add filepath to filename when moving it?

Hi I have a cron job setup that searches for 'core dump' files in a fixed set of directories and moves the core files to a separate file system. I am able to add date and time info to the file name. How can I add the source directory path to the file name? In case anyone is wondering why I... (5 Replies)
Discussion started by: dexter126
5 Replies

9. UNIX for Beginners Questions & Answers

Copy filepath along with filename at end of another file

Hi , Please help me out for the below problem - I have 2 files in a directory - $ ls -ltr total 4 -rwx------+ 1 abc Domain Users 615 May 31 17:33 abc.txt -rwx------+ 1 abc Domain Users 0 May 31 17:33 ll.sh I want to write the filename of abc.txt along with the directory to the... (2 Replies)
Discussion started by: Pratik4891
2 Replies

10. Shell Programming and Scripting

Extract filepath names between two strings

OS : Fedora Linux 26 Shell : bash I have a file with around 5000 lines like below. file /usr/share/icons/Papirus/16x16/actions/papirus-icon-theme-20180501-1.noarch conflicts with file ... file /usr/share/icons/Papirus/16x16/actions/align-horizontal-left-to-anchor.svg conflicts between... (7 Replies)
Discussion started by: John K
7 Replies
DIRNAME(3)						     Linux Programmer's Manual							DIRNAME(3)

NAME
dirname, basename - Parse pathname components SYNOPSIS
#include <libgen.h> char *dirname(char *path); char *basename(char *path); DESCRIPTION
The functions dirname and basename break a null-terminated pathname string into directory and filename components. In the usual case, dirname returns the string up to, but not including, the final '/', and basename returns the component following the final '/'. Trailing '/' characters are not counted as part of the pathname. If path does not contain a slash, dirname returns the string "." while basename returns a copy of path. If path is the string "/", then both dirname and basename return the string "/". If path is a NULL pointer or points to an empty string, then both dirname and basename return the string ".". Concatenating the string returned by dirname, a "/", and the string returned by basename yields a complete pathname. Both dirname and basename may modify the contents of path, so if you need to preserve the pathname string, copies should be passed to these functions. Furthermore, dirname and basename may return pointers to statically allocated memory which may be overwritten by subsequent calls. The following list of examples (taken from SUSv2) shows the strings returned by dirname and basename for different paths: path dirname basename "/usr/lib" "/usr" "lib" "/usr/" "/" "usr" "usr" "." "usr" "/" "/" "/" "." "." "." ".." "." ".." EXAMPLE
char *dirc, *basec, *bname, *dname; char *path = "/etc/passwd"; dirc = strdup(path); basec = strdup(path); dname = dirname(dirc); bname = basename(basec); printf("dirname=%s, basename=%s ", dname, bname); free(dirc); free(basec); RETURN VALUE
Both dirname and basename return pointers to null-terminated strings. BUGS
In versions of glibc up to and including 2.2.1, dirname does not correctly handle pathnames with trailing '/' characters, and generates a segmentation violation if given a NULL argument. CONFORMING TO
SUSv2 SEE ALSO
dirname(1), basename(1), GNU
2000-12-14 DIRNAME(3)
All times are GMT -4. The time now is 11:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy