Skip to main content

Posts

Showing posts from December, 2021

Grep in Unix

  Grep  in Unix   Grep is the frequently used command in Unix (or Linux). Most of us use grep just for finding the words in a file. The power of grep comes with using its options and regular expressions. You can analyze large sets of log files with the help of grep command. Grep stands for Global search for Regular Expressions and Print. The basic syntax of grep command is grep [options] pattern [list of files] Let see some practical examples on grep command. 1.  Running the last executed grep command This saves a lot of time if you are executing the same command again and again. !grep This displays the last executed grep command and also prints the result set of the command on the terminal. 2.  Search for a string in a file This is the basic usage of grep command. It searches for the given string in the specified file. grep "Error" logfile.txt This searches for the string "Error" in the log file and prints all the lines that

Sorting a file in unix

  Sorting a file  in Unix 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