Tuesday, February 15, 2011

Cygwin:- What is Cygwin & How to set up?

 "Cygwin is a Unix-like environment and command-line interface for Microsoft Windows" says Wiki. Programmers who wants to practice Unix usually install RedHat Linux in their PC's usually as a dual-boot or through VM. This process demands us to completely boot the OS before we start working. For users who are interested only in programming like C, C++, Java, Shell scripting, Perl scripting, etc.. we dont need to install the entire RedHat linux at all. Cygwin is the perfect alternative for you. Cygwin is a utility like any windows software. Once cygwin is installed, working on Unix is just like working on say a Microsoft word document. Just double click on the shortcut and you are inside the terminal. No need to wait for booting, etc. Cygwin installs every Unix command like a windows executable and hence invokes just like any windows utility.

Tuesday, February 8, 2011

sed - Replace or substitute file contents

 In one our earlier articles, we saw how to insert a line or append a line to an existing file using sed. In this article, we will see how we can do data manipulation or substitution in files using sed.

Let us consider a sample file, sample1.txt, as shown below:
apple
orange
banana
pappaya

Thursday, February 3, 2011

3 different ways of renaming a group of files

  While dealing with multiple file operations, it is very common to have a scenario where we would like to rename to set of files, say set of txt files to some other extension, or a set of non-extension files to a new 
extension, etc. In this article, we will see 3 different ways to rename the files.

1. To rename a set of stand alone files to a .txt extension. Assuming the directory contains the files file1, file2 and file3.

Wednesday, January 19, 2011

sed - Include or Append a line to a file

 sed is one of the most important editors we use in UNIX. It supports lot of file editing tasks. In this article, we will see a specific set of sed options.

Assume I have a flat file, empFile, containing employee name and employee id as shown below:
Hilesh, 1001
Bharti, 1002
Aparna, 1003
Harshal, 1004
Keyur, 1005

Tuesday, January 11, 2011

Positional parameters in a shell script

 Positional parameters in a shell script are nothing but the command line arguments passed to a shell script. The following are some of the positional parameters used:
$# -  Total number of arguments
$0 - Command or the script name
$1,$2, $3 - First, second and third args respectively.
$* - All the command line arguments starting from $1.