05-14-2008
Quote:
Originally Posted by
Nemelis
What he could not explain to me is why it finds the last dot in test.foo.extension and not the first dot (thus why it actually works). Since both "any number of characters" may contain dots (in theory) if I understand the man-pages (and his explanation) correctly.
In the sed command there is a saved substring "\(.*\)" wich we want and is recalled with "\1".
After this pattern we have "\..*" wich means a dot and everything after it.
Sed uses a greedy match (AKA longest match) so the saved substring will contain the part before the last "." in the substring.
Regards
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I want to use find to locate files with two different extensions, and run a grep on the results. The closest I have gotten is incredibly slow and ugly:
for i in `ls -laR|egrep -e '(.js|.css)'`; do find . -name $i -print|xargs grep -H searchBg; done;
This method makes my eyes bleed. Help! ;)
... (2 Replies)
Discussion started by: r0sc0
2 Replies
2. Shell Programming and Scripting
I have written a shell script and in my script i have a variable
filename=myfile.txt
now, i want another variable to be defined for which i have to strip out the extension fo the file name,
i.e. newvariable= myfile
how do i strip out the ".txt" part from my first variable.
Any kind of help... (4 Replies)
Discussion started by: ramky79
4 Replies
3. Shell Programming and Scripting
Hi,
I have files with names like file1.txt.txt.txt.txt and file2.txt.txt.txt.txt.txt............ (random infinite number of .txt exist).
how to truncate (mv) their names to ones with single .txt extension like file1.txt and file1.txt ? In other words, how to extract the filename upto first... (12 Replies)
Discussion started by: prvnrk
12 Replies
4. Shell Programming and Scripting
Friends
I want to automat sending a letter to different persons whose directories are named as 001, 002, 003, 004.
To push the same letter to all these directories, I need to name the letter as letter.001, letter.002 like that.
Is there any method whereby I get the extension of this letter... (2 Replies)
Discussion started by: chssastry
2 Replies
5. UNIX for Dummies Questions & Answers
I copied some files to another folder, and I want to change them from .doc extensions to .txt extensions. I tried using the cp and mv commands, but it didn't work. Is it possible to change file extensions with these commands, and if so how do I do it? I tried using the * wildcard (say cp *.doc... (1 Reply)
Discussion started by: Straitsfan
1 Replies
6. Shell Programming and Scripting
Hi all,
I have files in the filename pattern of,
this.is.the.name.of.my.file.mov
and I would like to remove dots (.) and replace them with spaces ( ) so the output would be,
this is the name of my file.mov
The other issue that I have is that the number of dots (.) in the file... (6 Replies)
Discussion started by: Monkey Dean
6 Replies
7. Shell Programming and Scripting
HI,
I have some csv files with mutiple extensions, I want to remove all the extensions and keep only the .csv extension.
anybody can suggest me how to do this.
source files
1.txt.csv.txt.csv.csv.txt.csv
2.csv.txt.csv.txt.csv.txt
target
1.csv
2.csv
--Wang (1 Reply)
Discussion started by: wangkc
1 Replies
8. Shell Programming and Scripting
hi all,
I want to remove filenames beginning with multiple dots.how I can do this.
Thanks in advance (5 Replies)
Discussion started by: sriharsharavi
5 Replies
9. Shell Programming and Scripting
Here is a simplified example of my problem. Say I have the following 3 sub-directories;
./folder1
A.txt
A.sh
./folder2
B.txt
./folder3
C.txt
C.sh
I would like to list the directory names which contain both '.txt' & '.sh' type extensions. I have came up with the following code;... (8 Replies)
Discussion started by: mmab
8 Replies
10. Shell Programming and Scripting
I am trying to get the file extension with file names that could contain multiple dots using shell scripting. I want to find a way using the sed command.
Example Filenames:
one.dat
one.dat.002
Results:
dat
I would like to return dat in both instances using the sed command. How can I... (4 Replies)
Discussion started by: smkremer
4 Replies
MEMMEM(3) Linux Programmer's Manual MEMMEM(3)
NAME
memmem - locate a substring
SYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <string.h>
void *memmem(const void *haystack, size_t haystacklen,
const void *needle, size_t needlelen);
DESCRIPTION
The memmem() function finds the start of the first occurrence of the substring needle of length needlelen in the memory area haystack of
length haystacklen.
RETURN VALUE
The memmem() function returns a pointer to the beginning of the substring, or NULL if the substring is not found.
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
+----------+---------------+---------+
|Interface | Attribute | Value |
+----------+---------------+---------+
|memmem() | Thread safety | MT-Safe |
+----------+---------------+---------+
CONFORMING TO
This function is not specified in POSIX.1, but is present on a number of other systems.
BUGS
In glibc 2.0, if needle is empty, memmem() returns a pointer to the last byte of haystack. This is fixed in glibc 2.1.
SEE ALSO
bstring(3), strstr(3)
COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
GNU
2017-03-13 MEMMEM(3)