shell


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

Related Links

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

Categories

HOME
oracle12c
facebook-oauth
delphi-7
ng-idle
depth
static-site
nested-if
settings
odoo-8
elasticsearch-5
extjs4.2
angular-dart
selenium-ide
scrolltop
magnetic-cards
docx
modbus-tcp
symfony-2.8
atlassian-stash
fileserver
google-picker
connector
user-experience
backpack-for-laravel
question2answer
string-concatenation
imageresizer
beta
draft-js-plugins
expressionengine3
beautifier
comparable
sqsh
panoramas
xbox
linkedhashmap
indy10
processwire
xajax
lint
recurrent-neural-network
microsoft-metro
chronicle-map
congestion-control
android-exoplayer
monkey-testing
snapchat
flask-restful
opennms
builder
aquamacs
yii2-user
seek
envi
google-cloud-console
tinkerpop3
dup
delta
simevents
appscale
shopping
yajsw
ellucian-scribe
grass
jbase
spring-retry
vigenere
ess
opserver
pax-exam
rdflib
skspritenode
teamcity-9.1
code-documentation
post-commit-hook
easyrtc
rickshaw
ios8-extension
cfcache
gae-quotas
http-patch
dtmf
printdialog
process-explorer
route-provider
font-awesome-4.0.0
alice
booksleeve
device-width
dopostback
android-loadermanager
qi4j
jquery-blockui
uimanageddocument
listitem
paginator
thttpd
mapping-by-code
window-decoration
qglwidget
strtod
web-application-project
linfu-dynamicproxy
change-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App