Showing posts with label grep. Show all posts
Showing posts with label grep. Show all posts

Wednesday, July 25, 2012

Most useful grep Options

-h:   suppress file names in output
-w:   restrict search to whole words only
-c:   displays count of matching lines in each file, not the lines themselves
      (note this is not the same as $ grep index *.rb | wc -l)
-i:   ignore case
-l:   list only file names containing matching lines
-n:   precede each line with the line number where it was found
-v:   display all lines NOT matching pattern
-C:   Display NUM lines of context either side of matches
-B:   Display NUM lines of context Before the matches
-A:   Display NUM lines of context After the matches

-e pattern: 
      Search for a pattern. Can use multiple times on a line
-r:   Search recursively from the current or specificed directory
  --include=pattern:
      Only search in file names matching pattern
  --exclude=pattern:
      Do not search in file names matching pattern

Friday, May 11, 2012

how to extract the definitions of indexes in an Oracle export file without connection to the database

Today I found myself in a situation where I needed definitions of indexes of an Oracle 9i database, but everything I had on me was an export file and no access to a database.

I discovered a simple way and without connection to a database to extract the definitions of indexes from an export file of an ORACLE database running on AIX 6.1


grep "CREATE INDEX" export_file.dmp > indexes_files.sql

This unix command will extract the indexes definition from the export file export_file.dmp and save it in a sql file indexes_files.sql


After that i needed to reformat the sql file and include a slash (/) after every definition in the file


cat achats_indexes.sql | awk '$0=$0 " \n/" {print $0}' >> output_indexes_files.sql

That's all, you can combine these two commands to create a shell script to extract indexes definition from oracle export files, taking 2 parameters : the export file and the sql output file.