Posterous theme by Cory Watilo

RUN ON LAST SUNDAY

RUN ON LAST SUNDAY

If you want a job to run on the last
sunday of every month, you can use
the following syntax from within cron:

18 * * * 0 [`date "+%d"` -gt 24] && /path/to/script

i.e. on sundays at 18:00 check if
the day of the month is greater than
24 - if so run the job (if 23 is
specified the job will run on the last
2 sundays of the month)

NOTE: There back-ticks around the date
command, not single quotes.

VI COPY FILE TO FILE

VI COPY FILE TO FILE

Here is how to copy the required number
of lines from one file to another in
VI editor.  First use the following
key combinations in the source file.

Press ESCAPE
Press Shift "(Shift double quotes)
Press a
Press the number of lines you want to copy
press y followed by another y

Now press " : " (COLON) to get the vi prompt.
Hit e "Destination file name"
Once you enter the Destination file
go to the line where you want the lines
copied to be inserted.

Press ESCAPE.
Press SHIFT "(Double quotes).
Press a.
Press p.

The lines get copied.

SEARCH SEVERAL FILES

SEARCH SEVERAL FILES

To search several files for a
string which you know sparsely,
the following searching technique
would be useful:

#grep <first part>.*<second part>.*<... part> <filenames>
       or,
#ls|xargs grep <first part>.*<second part>.*<... part>


This will print all the filenames
and lines which consists of
"<first part><0 to any number of
characters><second part><0 to any
number of characters><third part>
......"

For example, you want to search a
data structure among several header
files where it has been declared
not where it is being used.

If the data structure be XYZ, then
search will be:

#grep }.*XYZ  <filenames>

because you know it might be how
XYZ has been declared,
struct {
     .....
     .....
     }   XYZ
You don't know exactly how many
blank characters are there
unless you count them. But when XYZ
will be used it will be
done as follows(for example):

XYZ  *xyz;

and you don't want them to find out
as they will be coming
in several header or C files.


vim : use perldo

Use :perldo.



Here's how it works:


 :perldo lets you run perl scripts on the buffer text. vim iterates over

 all lines and aliases them to the Perl variable $_. To execute code just

 once at the beginning, use BEGIN {}.


 For example to replace all duplicate lines by a single space, type


     :perldo BEGIN{ %x=() } $_ = ' ' if $x{$_}++


 Note that %x will still be set on the next :perldo, so if you leave out

 the BEGIN{ } code, vim will delete *every* line on the second run.