You are not logged in.
Pages: 1
Hi,
I've started using egrep and have a problem. I've redirected all the files on my system to a text file, and to get the files longer than 10 characters ( excluding the path ) i use this grep command:
---------------------------------------
egrep '$[A-Za-z]{10,}' sysfiles.txt
---------------------------------------
But i think theres more to it than that.
I need to figure out how to place grep at the file name and NOT at the front of the line.
Could this be the fields?
What im thinking is that the '$' meta character puts grep at the last feild.
Offline
What does an entry look like?
Offline
Well what i've did is:
cat sysfiles.txt | cut -d"/" -f4 | egrep '[A-Za-z]{10,}$'
which gives the the system file name that is longer than 10 characters.
But i need to display the path. I cant cut it.
I need to tell grep that the path length doesnt matter, only the file itself.
Offline
So it's just filenames in there, I thought entire files for a second.
Well, you can match from start to the last / then. Because filenames don't contain /
egrep '^.*/[A-Za-z]{10,}$' sysfiles.txt
But what about dots or numbers in filenames?
Match for non-slashes instead:
egrep '^.*/[^/]{10,}$' sysfiles.txt
Offline
It works i tested it on a differnt file containing a path a few paths.
Thanks dude keep it up!
1 last question since your so helpful.
with this code:
---------------------------------------------------------------------------------------------
find / -type f -name '.bashrc' -print -exec grep PS1 '{}' \; 2>/dev/null | xargs ls -l
---------------------------------------------------------------------------------------------
Tells Bash:
find all the files in the system with a name ".bashrc" [ that part i know is right ]
But im not sure how to display the files that only modify the PS1 varaible
I have modified the PS1 varaible in the past, but wouldnt that only come up for bash_history?
Anyway, im getting ls: no such file or directory.
which makes sense because it isnt.
The rest of the code displays the path and protections which is most of what i need.
If you could help me out with the PS1 problem, that'd be cool, but its proven to be difficult
Offline
I know the thread you mean, but it was very confusing.
For the command you put there, you put a -print in it that will output your entire filesystem, and as Xyne said grep needs -l (not sure about -r/-R though), without it you will print the match which is not a file which will not work with ls -l
(Interestingly though, you can use grep -q, and put the -print AFTER the statement, so it will only run if grep was successfully, e.g. find / -exec grep -q PS1 '{}' \; -print | xargs ls -l)
Anyway, if you don't care about the filename, and using grep -l, you don't need find:
egrep -Rl '^PS1' / 2>/dev/null | xargs ls -l
Or
you want the permissions and path right? And been messing with cut, but if you try to determine the fields then a space in the path will mess it up.
So how about
find / -exec egrep -q '^PS1' '{}' \; -printf '%M %p\n' 2>/dev/null
(or octal permissions %m, add -name '.bashrc' for just bashrc files)
Well printf has some more fun stuff, look in man find.
Offline
Pages: 1