Tuesday, August 30, 2011

5 different ways to join all lines in a file

  In one of our earlier articles, we saw how to fold a file using the fold command. In this article, we will see the different ways in which we can unfold the file, or in other words, different ways to join all the contents of the file in one single line.

Let us take a file with the following contents. The file contains user's name and user expertise. Every line in the file is of length 16. The below shown examples are different ways of how to unfold the file contents:
$ cat file
Badri Mainframes
Suresh Unix
Rajendar Clist
Sreedhar Filenet

Thursday, August 25, 2011

Fold files using fold command

  It is possible at times we need to read a file which is not organized in the normal way. We are used to reading files which is line sequential meaning every record is present in a line. Sometimes, it may so happen when you receive a file from a different platform, such as mainframes, the file may be organized as record oriented, meaning all the records will be in the same line.

  We need to process these files differently. Let us assume we have a file which is record oriented in which each record is of length 16.
$ cat file
Satya MainframesManoj Unix      Manish Windows
   As shown above, all the records are in the same line.

Thursday, August 18, 2011

A Shell Script to do shell scripting faster

   Shell Scripting is all about automating a particular task, doing a task a bit faster than what it takes to do manually. However, when we write a shell script, if we notice properly, the amount of time we take to get it done is little more. In other words, can we think of ways in which we can write and test a shell script faster?

  Typically, when we write a shell script, we open the editor, write something, save and close it. Run the script. Depending on the output or some error thrown, open the file again, edit something, save and close it. Run the script, and this goes on and on and on. The focus here is the amount of time you spent on saving the file every time, running it, and again opening the file and repeating this whole process umpteen times. In some cases, while running, we get error, and by the time we re-open the file, we forget what the error is. Now, again run the script and see the error again and re-open it. The amount of time we spend here is pretty high.