Friday, May 30, 2014

FIND_IN_SET vs IN SQL commands

IN
This keyword is used to get data values equals to IN clause values.

Example :-

Select * from test_table where field_1 IN ('123','abc','873','345')

Above SQL returns values equals to 123,abc,873,345 in field_1.

FIND_IN_SET

Suppose you have a String values like "123,abc,873,345". You can use FIND_IN_SET to get IN clause supported string as '123','abc','873','345'.

Select * from test_table where field_1 FIND_IN_SET (',','123,abc,873,345')

This SQL is also return above IN SQL results.

Check highlighted values.

Wednesday, May 28, 2014

Split pipe separated column in Linux

Suppose you have a file that have pipe ("|") separated values.

122344|093462|45836
472391|093742|23444

If you want to split column 2 values, you can use the following command to get second column values easily.

cat log.txt | awk -F"|" '{print $2}'>second_column_log.txt

This will create a file called "second_column_log.txt" that contains column two values.

093462
093742

Check file differences in Linux

Following Linux command can be used to check two file line differences.
Before using the command you must sort the file using sort Linux command.

1.) sort err_file_1.txt > sorted_file_1.txt
2.) sdiff err_file_1.txt err_file_2.txt

Output will be shown in Linux terminal. You can write output to file using following command.

1.) sdiff err_file_1.txt err_file_2.txt >output.txt