grep -inRsH 'Text to be searched' /path/to/dir (it can be. If there is more than one dot, you'd need to check the end of the filename against a list of known multi-dot extensions in order to determine where to insert "_sample". This grep command will give you a precise result when you are searching for specific text on Linux. If there is only a single dot in the filename, then you could use your original code. So you'll need to be dealing exclusively with the filename, NOT the path AND filename! r means recursive searching, -l means listing file names only (without found text), -F means simple string mode searching, /path/to/directory indicates. NOTE: Make sure that the path has been stripped out - because it is possible that directory names in the path might also have a dot in them. So for example, in your script, you could first check to see how many dots are in the filename. If you have multiple dots, you'd probably have to filter the filename and look for specific extensions at the end. in the filesystem hierarchy all files that contain the string biblio in their name. ls /home/user/new/.txt prints all txt files in that directory. Although you can use this notation under bash, it is not common. So if you have more than one dot in the name, the simple regex you've used will not work. To show only file name without the entire directory path. But only for files with a single dot extension.īut it still wouldn't work for things like. If you ensure that you avoid using tons of dots in the filename and only reserve the dots for denoting the file-extension, then what you have will work as expected.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |