Monday 14 March 2016

Remove all Whitespaces from a file in Mac OS X

Lets look into a simple task today - remove all whitespaces from a file in Unix / Mac OS X from the command line.

To do so, let's consider a small example.

Let's have simple text file named Space_File.txt withe the below content. You see it's a regular text file with words separated with spaces.

1.Here is a cute little tutorial for
2.trying out different things using
3.the Stream Editor or Sed in Unix.
4.The author of this tutorial is
5.none other than IroncladWriter
6.himself. The tutorial aims to
7.teach folks and educate how
8.they could unlock the power
9.of Unix to the fullest. Am posting
10.this on the blog IronCladZone
11.The best blog on the whole of
12.internet, where you can learn
13.technical stuff as well enjoy 
14.entertaining tidbits like movies,
15.music, television, fashion, food,
16.shopping, travel, trends etc.
17.Just sit back, relax and

18.ENJOY THE RIDE :)

Now, we want to remove all the whitespace between the words. So let's use the following command.

tr -d ' \d' <Space_File.txt >NoSpace_File.txt

In this we pass the Space_Text.txt as input and redirect the output to a new file - NoSpace_File.txt. Note the space before \d. Do not miss this space. I repeat, DO NOT miss this space. It has to be ' \d' and not '\d'. Got it? All rite so the resultant output is as expected with no spaces:

1.Hereisacutelittletutorialfor
2.tryingoutifferentthingsusing
3.theStreamEitororSeinUnix.
4.Theauthorofthistutorialis
5.noneotherthanIronclaWriter
6.himself.Thetutorialaimsto
7.teachfolksaneucatehow
8.theycoulunlockthepower
9.ofUnixtothefullest.Amposting
10.thisontheblogIronClaZone
11.Thebestblogonthewholeof
12.internet,whereyoucanlearn
13.technicalstuffaswellenjoy
14.entertainingtibitslikemovies,
15.music,television,fashion,foo,
16.shopping,travel,trensetc.
17.Justsitback,relaxan

18.ENJOYTHERIDE:)

Monday 7 March 2016

Show line numbers in vi editor on Mac OS X

Guys in vi editor in order to show the line numbers, do the following :

Open vi editor to create or open a script
Click escape (esc) key and type colon.
Now enter set number and Enter

Check out the screenshot for reference :

Cheers!

Sunday 6 March 2016

User Input example in Python

Every programming language has a way to accept user input. Like in Perl, you accept using STDIN. Similarly, Python interpreter has 2 inbuilt functions to read user input :

raw_input()
input()

Let's look into a simple python script which accepts user input and prints a statement.
Create a simple script - vi python_input.py

#!/usr/bin/python

name = raw_input('Please enter your name, visitor : ');

print ('Welcome to IroncladZone ' + name);

You see the variable "name" stores the input entered by the user. Accordingly we make use of this value in the next print statement.

Output :

./python_input.py

Please enter your name, visitor : Johnny

Welcome to IroncladZone Johnny

Get Mac OS X System Information from Terminal

Hii! Guys lets come back today on another topic related to Apple Mac OS X. Correct me if am wrong, the first thing you would after purchasing your new Macbook or iMac is double-check the system information right?

Typically you would click the Apple logo on top left -> About this Mac -> System Report. Well could you get the same information from command line? Yes you can!

Open terminal and just type the following :

system_profiler

It will list the system information in a matter of few seconds. You could also filter the command to get only specific information by piping to a grep command.

For eg :

system_profiler | grep Memory

system_profiler | grep Processor

system_profiler | grep CPU

Saturday 5 March 2016

Maven : mvn package in Eclipse

Guys, as you maybe aware the command "mvn package" creates a package and stores it in the target directory. On the other side if you run "mvn install" it will create a package and then store it in your local repository.

I assume you have created a project from the archetypes from command line and then converted it to a Maven project after importing it in Eclipse.

Make sure the pom.xml has packaging set to jar by default. You could also change the package to war if needed.

Now simple right click the project to choose Run as -> Run Configurations.


Here you can specify the goals. In this case, we just want to create a simple package. So do this :


As you see, we also get various options for e.g. to build offline, skip tests, debug output etc. Now just enter the goals "clean package" and click Run.

You'll see that after a while a jar package gets created in the target directory of the project. Similarly if you run "clean install", it will install the jar to your local repository location. Make sure to double check the timestamp of the package from Terminal.

GRE GMAT CAT Wordlist - Set 1

Hello guys. From today onwards, apart from the regular technical posts, I'll also be starting a new series - GRE GMAT CAT Wordlists. From time to time I'll try to post unique sets of words with their meanings. The objective is to aid you guys for preparation of competitive exams like GRE GMAT CAT etc. The wordlists would really help you gain a competitive edge in the verbal and comprehension sections of the exams.

FYI these are inspired by Barron's GRE word reference. The only difference is that Barron's words  are sorted in alphabetical sequence. While I'll try to mix and match the words in any random sequence. Hope it helps.

Here are some casual tips to improve your English :
  • Try to memorise the words and their meanings. 
  • Try to use these words and construct sentences. If you read an article from a newspaper or magazine, try to incorporate the newly learned words in it and reconstruct a certain phrase or statement.
  • Definitely use flashcards. They help a lot in memorising the words.
  • Read lots of books and articles.
  • Watch lots of English movies and television soaps.
  • Socialise a lot and network around, all while speaking in English.
  • (Optional) Date around, flirt a lot and chat in English. Helps build confidence ;)
Ok let's get going guys. Here's the first set of 10 words for today.

amalgamate : combine together, unite
bard : poet
cadaver : dead body, corpse
clandestine : secret, something that's done secretly
adulterate : make something impure and of inferior quality, contaminate
altercation : noisy quarrel, noisy argument
belated : delayed
lacklustre : dull, boring, lacking shine or gloss
intangible : vague
gravity : seriousness, of importance

How to debug shell / bash scripts

While executing the bash scripts, if you want to debug them i.e you want to trace the exact sequence of steps that get executed, continue reading this post below.

Just below the shebang line on top of every script, type this :

set -x

That's it.

Let's take the example of killing a process / application using shell script that we saw in our previous post. Assuming you have opened the application - TextWrangler and want to close it using a bash script.

#!/bin/bash
set -x


kill -9 `ps -ef | grep TextWrangler | awk '{print $2}'`;

Now here's the output for the same :

++ ps -ef
++ grep TextWrangler
++ awk '{print $2}'

+ kill -9 24677 24678 24682

Note that 24677 24678 and 24682 are all PID's of all processes associated with TextWrangler. In this way you can track the flow of the script in which the tasks get executed. Debugging can be of great help if you have a complex flow of program and need to identify the sequence of steps in which they are executed.
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker