Sorting a file list returned by grep
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Sorting a file list returned by grep
Here is the catch...I need to sort according to last modified time so that oldest files come first...
I have looked at piping grep with sort but I am not sure what switches sort needs to sort by modified date ascending???
I have looked at piping grep with sort but I am not sure what switches sort needs to sort by modified date ascending???
Re: Sorting a file list returned by grep
man ls shows:
Also-t sort by modification time
--sort=WORD
extension -X, none -U, size -S, time -t, version -v, status -c,
time -t, atime -u, access -u, use -u
There are 10 types of people in this world, those who understand binary and those who don't
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Sorting a file list returned by grep
I know ls can do it...but the thing is the files are being returned by grep...
Re: Sorting a file list returned by grep
SoPCSpectra wrote:I know ls can do it...but the thing is the files are being returned by grep...
Code: Select all
grep "search_string" `ls -t`There are 10 types of people in this world, those who understand binary and those who don't
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Sorting a file list returned by grep
I am doing recursive grep:
Is what I was trying...
Code: Select all
grep -Rl 'Find Me' /var/www/project | sort -MRe: Sorting a file list returned by grep
Nice one
Code: Select all
grep "search_string" `find ./ -type f -printf "%A@ %p\n" | sort -nr | cut -d" " -f2`There are 10 types of people in this world, those who understand binary and those who don't
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Sorting a file list returned by grep
I hope you don't hate me...cause I always appreciate your linux assistance...your my informal GOTO guy whenever I have *nix questions...but
This was actually for a little TODO extractor script I wrote...I wanted to sort the lines based on last modified so that the oldest TODO were addressed first.
Then I decided that a human priority was probably best so I parse the line:
Using UltraEdit's built in scripting I have essentially given myself full server side searching capabilities that echo results to the Output Window which I can click and automatically find/jump to the line in question...
I do that hundreds of times a day so this will save me tons of time
While were on the subject though...
How do I make a PHP script executable from anywhere...
1. Give the script a shebang line -- done!
2. Mark the file as executable X bit -- Not done!
3. Add the path to the script to PATH as environment variable -- Not done!
Are the last two required? Does the last one need to be done each time the OS reboots?
Cheers,
Alex
This was actually for a little TODO extractor script I wrote...I wanted to sort the lines based on last modified so that the oldest TODO were addressed first.
Then I decided that a human priority was probably best so I parse the line:
Code: Select all
// TODO: This is non-critical TODO task so leave it as default priority
// TODO(123): This is a task that should be done before the previous TODO
I do that hundreds of times a day so this will save me tons of time
While were on the subject though...
How do I make a PHP script executable from anywhere...
1. Give the script a shebang line -- done!
2. Mark the file as executable X bit -- Not done!
3. Add the path to the script to PATH as environment variable -- Not done!
Are the last two required? Does the last one need to be done each time the OS reboots?
Cheers,
Alex
Re: Sorting a file list returned by grep
ThanksPCSpectra wrote:I hope you don't hate me...cause I always appreciate your linux assistance...your my informal GOTO guy whenever I have *nix questions...but
newer to older
Code: Select all
grep -h "search_string" `find ./ -type f -printf "%C@ %p\n" | sort -nr | cut -d" " -f2`Code: Select all
grep -h "search_string" `find ./ -type f -printf "%C@ %p\n" | sort -n | cut -d" " -f2`
Last edited by VladSun on Wed Oct 08, 2008 2:12 pm, edited 3 times in total.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Sorting a file list returned by grep
1. OKPCSpectra wrote:How do I make a PHP script executable from anywhere...
1. Give the script a shebang line -- done!
2. Mark the file as executable X bit -- Not done!
3. Add the path to the script to PATH as environment variable -- Not done!
Are the last two required? Does the last one need to be done each time the OS reboots?
2. You should make it executable.
3. Instead of modifying your PATH variable, try
Code: Select all
ln -s /path/to/your/PHP_script /usr/bin/name_hereAlso, you may edit the .bash_profile of each user's directory, and modify the PATH variable per user.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Sorting a file list returned by grep
Huh?
PCSpectra === Hockey?
PCSpectra === Hockey?
There are 10 types of people in this world, those who understand binary and those who don't