Since I started using this for searching strings I cannot dream of using anything else. I will put down some of the usual scripts I use wither with MINGW shell or Cygwin or even oracle to search data in a file or an oracle database.Think of it as a how to manual.
1. (Mingw) You want to filter the files on the command line which match two words?
Here I try to match the word FR_BLOCK and word starting with C from a list of files.
ls -lf | grep -iE "FR_BLOCK"| grep -iE "^C"
What this does is divided into 3 parts
ls -lf will list the directory contents in long format and remoe all extra information like date of creation and file size etc.
grep -iE "FR_BLOCK" The output of above command is piped to grep via | operator. The grep command will search for FR_BLOCK word and assumes matching with or without capital letters(i) and uses extended regular expressions(E).
The third part of grep -iE "^C" will search the piped out of the above command and searches for the file name where the starting alphabet is a C.
2. (Mingw) You want to know the time when a particular file has changed?
Use commands stat, grep and cut. For example here I find the time when the file filetime.sh has changed.
stat filetime.sh | grep 'Change:' | cut -f 3 -d ' '
stat will report a whole bunch of stats of the file. grep will return the line where word 'Change:' exists and cut commadn will cut the retunred string from grep into fileds (-f) at the 3rd point and assumes a delimiter (-d) of single space (' ').
3. (Mingw) You want to search for files and directories which end with 15 or 5 or 1
ls -l | grep -iE '[15]$'
1. (Mingw) You want to filter the files on the command line which match two words?
Here I try to match the word FR_BLOCK and word starting with C from a list of files.
ls -lf | grep -iE "FR_BLOCK"| grep -iE "^C"
What this does is divided into 3 parts
ls -lf will list the directory contents in long format and remoe all extra information like date of creation and file size etc.
grep -iE "FR_BLOCK" The output of above command is piped to grep via | operator. The grep command will search for FR_BLOCK word and assumes matching with or without capital letters(i) and uses extended regular expressions(E).
The third part of grep -iE "^C" will search the piped out of the above command and searches for the file name where the starting alphabet is a C.
2. (Mingw) You want to know the time when a particular file has changed?
Use commands stat, grep and cut. For example here I find the time when the file filetime.sh has changed.
stat filetime.sh | grep 'Change:' | cut -f 3 -d ' '
stat will report a whole bunch of stats of the file. grep will return the line where word 'Change:' exists and cut commadn will cut the retunred string from grep into fileds (-f) at the 3rd point and assumes a delimiter (-d) of single space (' ').
3. (Mingw) You want to search for files and directories which end with 15 or 5 or 1
ls -l | grep -iE '[15]$'
Comments
Post a Comment