Thursday, June 28, 2012

awk - 10 examples to split a file into multiple files

 In this article of the awk series, we will see the different scenarios in which we need to split a file into multiple files using awk. The files can be split into multiple files either based on a condition, or based on a pattern or because the file is big and hence needs to split into smaller files.

Sample File1:
Let us consider a sample file with the following contents:
$ cat file1
Item1,200
Item2,500
Item3,900
Item2,800
Item1,600

Tuesday, June 26, 2012

sed - 25 examples to delete a line or pattern in a file

In this article of  sed tutorial series, we are going to see how to delete or remove a particular line or a particular pattern from a file using the sed command.

 Let us consider a file with the sample contents as below:
$ cat file
Cygwin
Unix
Linux
Solaris
AIX
1. Delete the 1st line or the header line:
$ sed '1d' file
Unix
Linux
Solaris
AIX
      d command is to delete a line. 1d means to delete the first line.

Monday, June 25, 2012

A forum of The UNIX School

Dear Unix School Subscribers,
   Something which I have been thinking for quite some time, to have a dedicated forum for our blog is now ready, The UNIX School Forum.This forum is a place where-in you can get all your doubts clarified on Shell Scripting, sed, awk, perl, etc. All the users who till now have been sending mails to clarify their queries can simply post a question here and get the answer. So, what are you waiting for? Simply go the forum tab and post a question. 

Wednesday, June 20, 2012

Insert a line before or after a pattern

  In this article, we will see the different ways in which we can insert a line before or after on finding a pattern.  On finding the pattern 'Fedora', the requirement is to insert a line:
  • before the pattern 
  • after the pattern.
Let us consider a file with the following contents:
$ cat file
Linux
Solaris
Fedora
Ubuntu
AIX
HPUX
Inserting before the pattern:

Monday, June 18, 2012

Shell script to send birthday reminder e-mails

   In a professional work place, it is pretty common to celebrate the birthdays of your colleagues. Somebody in the team will have the birthdays maintained in a file and they will let the team know when the day arrives. The issue here is it is quite possible to miss out if one forgets to check the birthday file. How nice it will be if you can get an e-mail reminder of the person celebrating their birthday? Let us see in this article how to create a shell script which will send us an e-mail stating the names of the people celebrating their birthdays. Also, the same script with little modifications can be used to set reminder for any other purpose.

  This article discusses about 3 scripts:
  • Shell Script to get reminder on the list of users having their birthday today.
  • Shell  Script to get reminder on the list of users having their birthday the next day or some other day.
  • Shell  Script to get reminder on the list of all users having their birthday over the next n days.