Wednesday, August 7, 2013

Some LINUX commands

1.Checkout:

svn checkout svn:/svn/automation_project/trunk .
 
2.compile in unix
javac -classpath commons-net-3.1.jar:mysql-connector-java-5.1.13-bin.jar:jxl.jar:servlet-api.jar DBConnection2.java
 
3.set classpath in unix
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin 
 
To compare two files ignoring differences in the case of the letters and blank spaces:
diff -iw part1 part_one
 
 

Sort Command Examples

Sort command in unix or linux system is used to order the elements or text. Sort command has the capability of sorting numerical values and strings. The sort command can order the lines in a text file.

The syntax of sort command is:

sort [options] filename
The options are:

-b : Ignores leading spaces in each line -d : Uses dictionary sort order. Conisders only spaces and alphanumeric characters in sorting -f : Uses case insensitive sorting. -M : Sorts based on months. Considers only first 3 letters as month. Eg: JAN, FEB -n : Uses numeric sorting -R : Sorts the input file randomly. -r : Reverse order sorting -k : Sorts file based on the data in the specified field positions. -u : Suppresses duplicate lines -t : input field separator
Sort Command Examples:

Before practicing the examples create the below two files in your unix system:

> cat order.txt Unix distributed 05 server Linux virtual 3 server Unix distributed 05 server Distributed processing 6 system > cat delim_sort.txt Mayday|4 Janmon|1 Declast|12
1. Sorting lines of text

The default sort command uses alphabetical order (ASCII order) to sort the file. It treats each line as a string and then sorts the lines.

> sort order.txt Distributed processing 6 system Linux virtual 3 server Unix distributed 05 server Unix distributed 05 server
2. Sorting based on the field positions.

You can specify the field positions using the -k option of sort command. The sort command uses the space or tab as the default delimiter. To sort based on the data in the second field, run the below command:

> sort -k2 order.txt Unix distributed 05 server Unix distributed 05 server Distributed processing 6 system Linux virtual 3 server
You can also specify more than field with k option as a comma separated list. The below command uses the second and fourth fields to sort the data.

> sort -k2,4 order.txt
3. Numeric sorting

Instead of the default alphabetical sorting order, you can make the sort command to sort in numeric order using the -n option. This is shown below:

> sort -nk3 order.txt Linux virtual 3 server Unix distributed 05 server Unix distributed 05 server Distributed processing 6 system
4. Sort in reverse order

By default, the sort command sorts the data in ascending order. You can change this to descending order using the -r option.

> sort -nrk3 order.txt Distributed processing 6 system Unix distributed 05 server Unix distributed 05 server Linux virtual 3 server
5. Suppressing duplicates or Print only unique values

You can produce only unique values in the output using the - u option of the sort command.

> sort -u order.txt Distributed processing 6 system Linux virtual 3 server Unix distributed 05 server
Another way is piping the output of sort command to uniq command.

> sort order.txt | uniq
6. Delimited file input

In the second, third and fourth examples we have sorted the data based on the field positions. Here the fields are separted by space or tab character. What if the fields are specifed by any other character? In such cases, we have to specify the input delimiter with the -t option. An example is shown below:

> sort -t'|' -nrk2 delim_sort.txt Declast|12 Mayday|4 Janmon|1
7. Sorting on months.

We can sort the data in the monthwise using the -M option of the sort command. This is shown below:

> sort -M delim_sort.txt Janmon|1 Mayday|4 Declast|12
 
Taken from http://www.folkstalk.com/2012/08/sort-command-examples-in-unix-linux.html
 
 
 

sed Case Insensitive Search Matching

 sed -e s/o1sales/o1adops/gI input_report_url.csv >i.csv 
 

No comments:

Post a Comment