Your desired output is inconsistent. You want the trailing /, or not? grep -o can do the same thing, probably more efficiently, but -o is possibly not portable, depending on where you plan to use it.
Thank you very much for the quick answer. It worked like a charm.
Edit: both suggestions work, I will see which I will use when doing the deep tests.
Edit2: Yes, I know about the grep, but I cannot use grep in my script logic. The directories get extracted via lsof or pfiles.
Seems I'm inundating this forum with questions, but anyway:
I am writing a script that should accept one and only one argument when called.
That argument should designate a file, either with path/filename or just filename.
Now to the difficult bit:
I want to figure out a way to store... (9 Replies)
The line is simple, use " '{ print $1"]"$2"\"$3THE " NEEDS TO GO HERE$4 }'
I've tried \", "\, ^" and '"" but none of it works. What am I missing? Putting in the [ between $1 and $2 works fine, I just need to do the same with a ".
Thanks. (2 Replies)
Hi
I am trying to use sed to retrieve part of my html file's path. I am having a hard time getting what I want. Could someone give me some help?
I want to retrieve the section after html and before the file name
For example if I have the following, ... (3 Replies)
I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction?
for FILE in `cat list`; do
if ;
then
... (1 Reply)
Can any one tell me that how can i print all directory with their path in a given parent directory.
i.e. parent directory /home/usr/
Now this shoe directory may contain sevral directory
/home/usr
dir1/
dir1.1/
dir1.2/
dir2
dir2.1/
dir2.2/
... (5 Replies)
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)
hi,
i have a directory at /path/unix with the following files
1.txt
2.txt
3.txt
4.txt
I want to make another file called filenames.txt at a different location called /path/home. So, my output file would be
/path/home/filenames.txt with contents
/path/unix/1.txt... (1 Reply)
My input is as below :
/splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt
/splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt
/splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt
/splunk/scrubbed/triumph/ifind.triumph.txt
From the above input I want to extract the file names only .
Basically I want to... (5 Replies)
Hello,
I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies
LEARN ABOUT MOJAVE
exchangedata
EXCHANGEDATA(2) BSD System Calls Manual EXCHANGEDATA(2)NAME
exchangedata -- atomically exchange data between two files
SYNOPSIS
#include <unistd.h>
#include <sys/attr.h>
int
exchangedata(const char * path1, const char * path2, unsigned int options);
DESCRIPTION
The exchangedata() function swaps the contents of the files referenced by path1 and path2 in an atomic fashion. That is, all concurrent pro-
cesses will either see the pre-exchanged state or the post-exchanged state; they can never see the files in an inconsistent state. The data
in all forks is swapped in this way. The options parameter lets you control specific aspects of the function's behaviour.
Open file descriptors follow the swapped data. Thus, a descriptor that previously referenced path1 will now reference the data that's acces-
sible via path2, and vice versa.
In general, the file attributes (metadata) are not exchanged. Specifically, the object identifier attributes (that is, the ATTR_CMN_OBJID
and ATTR_CMN_OBJPERMANENTID attributes as defined by the getattrlist(2) function) are not swapped. An exception to this general rule is that
the modification time attribute ( ATTR_CMN_MODTIME ) is swapped.
When combined, these features allow you to implement a 'safe save' function that does not break references to the file (for example,
aliases). You first save the new contents to a temporary file and then exchange the data of the original file and the temporary. Programs
that reference the file via an object identifier will continue to reference the original file, but now it has the new data.
The path1 and path2 parameters must both reference valid files. All directories listed in the path names leading to these files must be
searchable. You must have write access to the files.
The options parameter is a bit set that controls the behaviour of exchangedata(). The following option bits are defined.
FSOPT_NOFOLLOW If this bit is set, exchangedata() will not follow a symlink if it occurs as the last component of path1 or path2.
RETURN VALUES
Upon successful completion a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error.
COMPATIBILITY
Not all volumes support exchangedata(). You can test whether a volume supports exchangedata() by using getattrlist(2) to get the volume
capabilities attribute ATTR_VOL_CAPABILITIES, and then testing the VOL_CAP_INT_EXCHANGEDATA flag.
ERRORS
exchangedata() will fail if:
[ENOTSUP] The volume does not support exchangedata().
[ENOTDIR] A component of the path prefix is not a directory.
[ENAMETOOLONG] A component of a path name exceeded NAME_MAX characters, or an entire path name exceeded PATH_MAX characters.
[ENOENT] Either file does not exist.
[EACCES] Search permission is denied for a component of the path prefix.
[ELOOP] Too many symbolic links were encountered in translating the pathname.
[EFAULT] path1 or path2 points to an invalid address.
[EXDEV] path1 and path2 are on different volumes (mounted file systems).
[EINVAL] path1 or path2 reference the same file.
[EINVAL] You try to exchange something other than a regular file (for example, a directory).
[EIO] An I/O error occurred while reading from or writing to the file system.
SEE ALSO getattrlist(2), rename(2)HISTORY
A exchangedata() function call appeared in Darwin 1.3.1 (Mac OS X version 10.0). It was deprecated in macOS 10.13.
Darwin December 15, 2003 Darwin