Timeline for Grep a directory and return list with line numbers
Current License: CC BY-SA 3.0
        13 events
    
    | when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 30, 2011 at 7:15 | comment | added | Matteo | I was just being over-precise: I would assume the same, I almost never used the -Z flag anyway :-) | |
| Nov 30, 2011 at 6:59 | comment | added | jaypal singh | 
        
            
    True, I assumed that the file name won't have :. Crap! :)
        
     | 
|
| Nov 30, 2011 at 6:43 | comment | added | Matteo | @Jaypal GPT_Parser.sh does not contain a ':' character. awk splits on : how could it recognize if the : is part of the name? Or did I miss something? Try with a file named "test:file:with:.txt" | |
| Nov 30, 2011 at 6:41 | comment | added | jaypal singh | 
        
            
    Why would it Matteo, I tried this on my computer and got this - [jaypal:~/Temp] grep -n -r "*p*" ./ | awk -F: '{print $2,$1}' 50 ./backup/GTP_Parser.sh 55 ./backup/GTP_Parser.sh
        
     | 
|
| Nov 30, 2011 at 6:36 | comment | added | Matteo | @Jaypal the -Z is there to be able to recognize filenames with a : in the name itself. The last solution would strip part of files like "Report: January.txt" | |
| Nov 30, 2011 at 3:38 | comment | added | jaypal singh | 
        
            
    Ahh you are correct. It should be grep -n -r $pattern $path | awk -F: '{print $2,$1}'
        
     | 
|
| Nov 30, 2011 at 2:47 | comment | added | Arcege | 
        
            
    Wouldn't the -Z and -F: not match here, @Jaypal ?  You would want to replace the \0 character explicitly: grep -rZn "$pattern" "$path" | awk -F: {sub(/\0/,":",$1);print $1}'
        
     | 
|
| Nov 29, 2011 at 22:18 | comment | added | jaypal singh | 
        
            
    or pipe it to awk like this  grep -rZn $pattern $path | awk -F: '{print $2,$1}' and get pretty results! :)
        
     | 
|
| Nov 29, 2011 at 21:59 | vote | accept | Zack Hovatter | ||
| Nov 29, 2011 at 21:59 | vote | accept | Zack Hovatter | ||
| Nov 29, 2011 at 21:59 | |||||
| Nov 29, 2011 at 21:58 | comment | added | Zack Hovatter | 
        
            
    Awesome - thanks much for that. Especially including the sed bit.
        
     | 
|
| Nov 29, 2011 at 21:14 | history | edited | Matteo | CC BY-SA 3.0 | 
        
            
             
                
                    sed example 
                
             
        
     | 
| Nov 29, 2011 at 21:05 | history | answered | Matteo | CC BY-SA 3.0 |