IP

Showing posts with label LINUX 101 HACKS. Show all posts
Showing posts with label LINUX 101 HACKS. Show all posts

LINUX HACK 21


Hack 21. Change the Case

Convert a file to all upper-case:


$  cat  employee.txt
100  Jason  Smith

200  John  Doe

300  Sanjay  Gupta

400  Ashok  Sharma

$  tr  a-z  A-Z  <  employee.txt

100  JASON  SMITH

200  JOHN  DOE

300  SANJAY  GUPTA
400  ASHOK  SHARMA


Convert a file to all lower-case:


$  cat  department.txt
100  FINANCE

200  MARKETING

300  PRODUCT  DEVELOPMENT

400  SALES

$  tr  A-Z  a-z  <  department.txt

100  finance

200  marketing

300  product  development

400  sales



LINUX HACK 20


Hack 20. Join Command


Join command combines lines from two files based on a common field.

In the example below, we have two files – employee.txt and salary.txt. Both have employee-id as common field. So, we can use join command to combine
the data from these two files using employee-id as shown below.

 
$  cat  employee.txt
100  Jason  Smith

200  John  Doe

300  Sanjay  Gupta

400  Ashok  Sharma

$  cat  bonus.txt

100  $5,000

200  $500

300  $3,000

400  $1,250

$  join  employee.txt  bonus.txt

100  Jason  Smith  $5,000

200  John  Doe  $500

300  Sanjay  Gupta  $3,000

400  Ashok  Sharma  $1,250




LINUX HACK 19

Hack 19. Suppress Standard Output and Error

Message


Sometime while debugging a shell script, you may not want to see either the standard output or standard error message. Use /dev/null as shown below for suppressing the output.


Suppress standard output using > /dev/null


This will be very helpful when you are debugging shell scripts, where you don’t want to display the echo statement and interested in only looking at the error messages.
 
#  cat  file.txt  >  /dev/null

#  ./shell-script.sh  >  /dev/null 

Suppress standard error using 2> /dev/null


This is also helpful when you are interested in viewing only the standard output and don’t want to view the error messages.
 
#  cat  invalid-file-name.txt  2>  /dev/null

#  ./shell-script.sh  2>  /dev/null