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
Error while extracting data from log file
Are multiple redirects within an AND-OR list valid in POSIX shell syntax?
Shell command to rename files with ? inside name
How to apply unix2dos on last modified file?
Extract data from log [duplicate]
Is ksh on AIX in violation of POSIX.1-2004 and POSIX.1-2008?
get the number of seconds left for the sleep command to end in a shell script
Scheduling a script
Error with shell script
Using shell script which checks if the user has logged in twice into Unix server and displays the details of the users
bad time argument filename in tmpwatch
how can we get a word in "double quotes using shell script
ssh: execute several commands
How to do in place replacement into another file in unix shell scripting
How can I pass values from a file to parameters in a shell command?
replace a pipe delimited column using awk