find and grep command this but not that
I am trying to find all the files which are not the *.o (object) files and store in file MyFile.lst in the current directory Tree. I am doing it from using below command. #! /usr/bin/ksh find . -type f | grep -v "*.o" >> MyFile.lst For some reason it is not working please help me. Edit: find . -type f | grep -v '\.o$' >> MyFile.lst Seems like working. Any comment/ suggestion.(added keith.layne correction)
You don't need grep. find . -type f '!' -name '*.o' >> MyFile.lst In grep, the searching pattern should be a regular expression. Therefore, ., $ and * are having special meaning. . means match any character $ means match the end of a line X* means match X, zero or more times(greedy) grep -v '\.o$' would match files with .o extension. (You need to escape . for its literal meaning).
Your edit should be fine...$ (as I'm sure you know) should match the end of the line. You should make one change, however: escape the . (a wildcard) with a \. Otherwise you'll match for example a file named 'Mo'. I think (from a quick test) that grep treats * as a literal at the beginning of a pattern. Your script will now be: #! /usr/bin/ksh find . -type f | grep -v '\.o$' >> MyFile.lst
find . -not -name "*.o" -type f >> list
Adjust PDF canvas maximum page size
Convert date and time to seconds
Oozie shell action doesn't send mail notification
How to get the impala query output log into a variable using unix shell script?
teradata table error using multiload script
awk command to print multiple columns using for loop
Bash Script for loop?
why one bteq script works, but not the other
CoovaChilli redirect to a new page on successfull login, to display user account balance
First and last days of month given a specific day of that month - shell
wget downloads files from FTP site TWICE
Ignore input_userauth_banner when running ssh-copy-id
What does >& means in the following code snippet
shell script “syntax error: `done' unexpected.”
shell script compare numbers return illegal number
Read file, pick field values and make it tab delimited