Archive for May, 2010

SQL Command to copy the result to a file

Being more Concerned about the queries and saving their results in sql i found out a way to save the results directly into a file through the command in desired format.

Here it goes:

mysql> select emp_id,emp_name from emps

into outfile ‘c:/test.txt’;

This simply produces the file without any fuss,each column output as in the table.

We can also manipulate the file by simply formatting the output of the sql,so if we wanted to output each column in the table with a comma delimeter we would have to concatenate the values together in the SQL to produce the required result.In mysql there are number of options we can use with INTO OUTFILE to change the  way data is written to the file.These are FIELDS ESCAPED BY,FIELDS ENCLOSED BY,FIELDS TERMINATED BY.So if we wanted our output to be enclosed in double quotes,with comma delimiters and a new line termination for eac row we would use.

Select emp_id,emp_name

INTO OUTFILE  ‘c:/result.text’

FIELDS TERMINATED BY ‘,’   ENCLOSED BY  ‘  ”  ‘

LINES TERMINATED BY  ‘ \n ‘

FROM emps;

That is it.....
Hope it Helps :)

Leave a Comment

Linux grep Command

I already listed few find commands in my previous post but i found they are of not much use when i want to search for a particular string/Word in a Directory.

Was really in need of such a command at ma workplace and then i encountered this  simple comamnd to do this after some browsing…And as Usual i am here to share this with you..

grep -r “String” /filepath…This would search the word in the specified path ex: “c/users/bin”

OR

grep -r “String” *..this would search in all directories

String here is the specific word with which you want to search with

FilePath is the directory where you want the command  to search the specified word.

Hope It helps…:) 🙂

Wud luv to hear comments….

Leave a Comment