Sponsored Content
Full Discussion: Strip part from filename
Top Forums UNIX for Dummies Questions & Answers Strip part from filename Post 302299965 by Franklin52 on Sunday 22nd of March 2009 04:41:58 PM
Old 03-22-2009
To understand the command you must have some basic knowledge of sed, but here we go:

Code:
sed 's/.*[-_]\(.*\)/mv & \1/'

With sed you can save substrings with \(.*\) and recall them back with \1, \2, \3 etc.

Here we saved a portion \(.*\) after the regular expression:

Code:
.*[-_]

This regexp means one or more characters ending with a "-" or "_" so the saved portion \(.*\) contains the characters after the last "-" or "_"

We substitute the string matched by the regular expression with:

Code:
mv & \1

& is a character with a special meaning and is replaced with the string matched by the regular expression.

\1 is the recalling of the saved portion \(.*\)


Regards
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strip extention from filename

Hey, How to strip the extention from filename? MY_XML.xml -> MY_XML MY_TEST_FILE.txt -> MY_TEST_FILE HELLO_WORLD.xls -> HELLO_WORLD Thanks in advance! (2 Replies)
Discussion started by: mpang_
2 Replies

2. Shell Programming and Scripting

part of a filename

Hi, I need to extract only a part of the filenames of some files. The files are named this way : .tap_profile_SIT02 I want the "SIT02" part, which is not the same for each file. I was able to get what I want with bash, but not with ksh. Here is the command I used in bash : find... (8 Replies)
Discussion started by: flame_eagle
8 Replies

3. Shell Programming and Scripting

detecting the part of a filename

I like to have the date in the 2008-09-01 format at the beginning of my filenames. I then hyphenate after that and then have my filename. I have a script that creates this for me. However, I may be working on files that already have the date format already in there and so I don't want to have a... (4 Replies)
Discussion started by: mainegate
4 Replies

4. Shell Programming and Scripting

How to strip off the leading filename from 'wc -l' command

Hi... can anyone please tell how do i strip off the leading filename from the wc -l command.... when i fire command wc -l new1 ... its giving output as 14 new1 i want the output as just '14'... i need to use this value in the calculations in the later part of the script..... (2 Replies)
Discussion started by: swap21783
2 Replies

5. Shell Programming and Scripting

Getting part of a filename

Hi All, I'm trying to get part of a filename and my skill with regular expression are lacking. I know I need to use SED but have no idea how to use it. I'm hoping that someone can help me out. The file names would be: prefix<partwewant>suffix.extension the prefix and suffix are always 3... (4 Replies)
Discussion started by: imonkey
4 Replies

6. Shell Programming and Scripting

cut the some part in filename

Hi All, I have the file & name is "/a/b/c/d/e/xyz.dat" I need "/a/b/c/d/e/" from the above file name. I tryning with echo and awk. But it not come. Please help me in this regard. Thanks & Regards, Dathu (3 Replies)
Discussion started by: pdathu
3 Replies

7. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

8. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

9. Shell Programming and Scripting

Finding the part of a filename

Hi, I am writing an ebuild for Gentoo Linux operating system. Writing an ebuild is about Bash scripting where I am a newbie. So, my ebuild must find a part of a specific filename. Such a filaname my look like this: libvclient_release_x64.so.740and I must to find the number at the and of... (18 Replies)
Discussion started by: csanyipal
18 Replies
EXTATTR_GET_FILE(2)					      BSD System Calls Manual					       EXTATTR_GET_FILE(2)

NAME
extattr_get_fd, extattr_set_fd, extattr_delete_fd, extattr_list_fd, extattr_get_file, extattr_set_file, extattr_delete_file, extattr_list_file, extattr_get_link, extattr_set_link, extattr_delete_link, extattr_list_link -- system calls to manipulate VFS extended attributes LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/types.h> #include <sys/extattr.h> ssize_t extattr_get_fd(int fd, int attrnamespace, const char *attrname, void *data, size_t nbytes); int extattr_set_fd(int fd, int attrnamespace, const char *attrname, const void *data, size_t nbytes); int extattr_delete_fd(int fd, int attrnamespace, const char *attrname); ssize_t extattr_list_fd(int fd, int attrnamespace, void *data, size_t nbytes); ssize_t extattr_get_file(const char *path, int attrnamespace, const char *attrname, void *data, size_t nbytes); int extattr_set_file(const char *path, int attrnamespace, const char *attrname, const void *data, size_t nbytes); int extattr_delete_file(const char *path, int attrnamespace, const char *attrname); ssize_t extattr_list_file(const char *path, int attrnamespace, void *data, size_t nbytes); ssize_t extattr_get_link(const char *path, int attrnamespace, const char *attrname, void *data, size_t nbytes); int extattr_set_link(const char *path, int attrnamespace, const char *attrname, const void *data, size_t nbytes); int extattr_delete_link(const char *path, int attrnamespace, const char *attrname); ssize_t extattr_list_link(const char *path, int attrnamespace, void *data, size_t nbytes); DESCRIPTION
Named extended attributes are meta-data associated with vnodes representing files and directories. They exist as "name=value" pairs within a set of namespaces. The extattr_get_file() system call retrieves the value of the specified extended attribute into a buffer pointed to by data of size nbytes. The extattr_set_file() system call sets the value of the specified extended attribute to the data described by data. The extattr_delete_file() system call deletes the extended attribute specified. The extattr_list_file() returns a list of attributes present in the requested namespace. Each list entry consists of a single byte containing the length of the attribute name, followed by the attribute name. The attribute name is not terminated by ASCII 0 (nul). The extattr_get_file() and extattr_list_file() calls consume the data and nbytes arguments in the style of read(2); extattr_set_file() consumes these arguments in the style of write(2). If data is NULL in a call to extattr_get_file() then the size of defined extended attribute data will be returned, rather than the quantity read, permitting applications to test the size of the data without performing a read. The extattr_delete_link(), extattr_get_link(), and extattr_set_link() system calls behave in the same way as their _file counterparts, except that they do not follow symlinks. The extattr_get_fd(), extattr_set_fd(), and extattr_delete_fd() calls are identical to their "_file" counterparts except for the first argu- ment. The "_fd" functions take a file descriptor, while the "_file" functions take a path. Both arguments describe a file associated with the extended attribute that should be manipulated. The following arguments are common to all the system calls described here: attrnamespace the namespace in which the extended attribute resides; see extattr(9) attrname the name of the extended attribute Named extended attribute semantics vary by file system implementing the call. Not all operations may be supported for a particular attribute. Additionally, the format of the data in data is attribute-specific. For more information on named extended attributes, please see extattr(9). RETURN VALUES
If successful, the extattr_get_file() and extattr_set_file() calls return the number of bytes that were read or written from the data, respectively, or if data was NULL, then extattr_get_file() returns the number of bytes available to read. If any of the calls are unsuccess- ful, the value -1 is returned and the global variable errno is set to indicate the error. The extattr_delete_file() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
The following errors may be returned by the system calls themselves. Additionally, the file system implementing the call may return any other errors it desires. [EFAULT] The attrnamespace and attrname arguments, or the memory range defined by data and nbytes point outside the process's allo- cated address space. [ENAMETOOLONG] The attribute name was longer than EXTATTR_MAXNAMELEN. The extattr_get_fd(), extattr_set_fd(), and extattr_delete_fd() system calls may also fail if: [EBADF] The file descriptor referenced by fd was invalid. Additionally, the extattr_get_file(), extattr_set_file(), and extattr_delete_file() calls may also fail due to the following errors: [EACCES] Search permission is denied for a component of the path prefix. [ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. [ENOENT] A component of the path name that must exist does not exist. [ENOTDIR] A component of the path prefix is not a directory. SEE ALSO
getextattr(1), extattr(3), extattr(9) HISTORY
Extended attribute support was developed as part of the TrustedBSD Project, and introduced in FreeBSD 5.0 and NetBSD 3.0. It was developed to support security extensions requiring additional labels to be associated with each file or directory. CAVEATS
This interface is under active development, and as such is subject to change as applications are adapted to use it. Developers are discour- aged from relying on its stability. Note that previous versions of this man page incorrectly stated that extattr_list_file() returned a list of attribute names separated by ASCII 0 (nul). BSD
August 3, 2011 BSD
All times are GMT -4. The time now is 06:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy