Posts Tagged ‘command’

Vi Editor Shortcuts

Posted: February 12, 2014 in Linux
Tags: , , , , ,

As we are aware, VI editor works in two mode . One is the Command mode which runs when we press Escape button and give commands and the other one is the insert mode which runs when we press i and type something up.

For a single window option we can always press : and type our command to be executed. One common command is :se nu. Which is the set line number commmand . But, once you quit the window and come back . It will be gone forever.

For making the changes permanent we need to put the commands in .vimrc file. Just type cd to move on to your home folder and open the file .vimrc .

$cd
$vi .vimrc
set number

We can also set abbreviations in vimrc file. Some of the frequently used words can be set here.

For example : select * from

When writing queries we will be using select * from quite often . Hence just set the abbreviation in vimrc file as below

iab sel select * from

Once you type sel and hit a space , vi will replace it to select * from .

vimrc file will be invoked when the terminal is loaded. For the effects to be applied on the same terminal where we changed vimrc we need to give the source command

source .vimrc

Or we can just close the existing terminal and open a new one.

Advertisements

For extracting lines from file use sed commmand in linux

sed -n '10p,20p' input.txt > output.txt

in the above command -n represent lines and 10 and 20 represents the offset , input.txt is the file from which we are extracting the input and storing the output in output.txt

say if i just need the nth line , then use the command as

sed -n '10p' input.txt > output.txt

The above command will extract only the 10th line

if i need selected lines say 10,15,17

sed -n '10p;15p;17p' input.txt > output.txt

Note : Be careful when you are using the > operator . If it is misplaced entire file will get erased.

Just for calculating n days/months/year from a date use the following linux command

date -d "(+/-)(Number) (Day/Month/Year)"

Date Manip

Useful unix command

Posted: April 11, 2013 in Linux
Tags: , , , , , ,

Lets write a simple unix command to list all java files which contains the word “sample”

 
find -nam "*.java" | xarg grep "sample" -ril

find -name “*.java” will search all the java files. “|” will be used to redirect the output of the first command to next , one by one. Now, in that we are searching for the word sample . -r is used to make a recursive search . -i is to make a Case Sensitive search and -l is used for listing the file names alone.
error

OOPS. something went wrong.. What was that ???? I mispelt name. What should i do now? rewrite the command ? Use up and arrow keys for editing the entire command.No need at all. When ever you want to replace something in your command stick to this pattern

^foo^bar

since we have mispelt name our command should be

^nam^name

correction

This command is used to convert Unix time stamp to date time .


Duetime 1185182001
[/ sourcecode]

This Will show result as

Monday,July 23, 2007 14:23:21
[/ sourcecode]