вторник, 5 июля 2011 г.

Shell: following a keyword in a constantly updated file

We can follow a file on the screen with the command:

tail -f /var/myfile


But if we are looking for only some specific keywords we can use the following command:

tail -f /var/myfile | fgrep --color -C 4 'keyword'


Here the "--color" means to highlight the found keyword.
And "-C 4" means to print 4 lines above and below the found keyword.

четверг, 4 марта 2010 г.

Bash and textarea checking

Recently i got a task to write a simple javascript checking of the textarea field which can be filled with maximum 250 chars.

I wrote a regular expression /^.{0, 250}$/ and where can take quickly an example of text with 250 chars?

Simple Bash script was a quick decision:
for i in {1..250}; do echo -ne "a"; done

Just wondered again how it is cool.

вторник, 16 февраля 2010 г.

Copying folder structure without .svn files

Sometimes i need to get a working copy of my project without .svn files added automatically by Subversion.

I have now 3 ways to do this:

The first way is just to use the Export functionality of the Subversion itself.

The second way is to use Total commander and its tool "Synchronize directories" which allows to compare folders and make them identical. In the top area of the "Synchronize directories" window there is a field to insert a filter like *.php which says that we want to compare only php files.

To solve our task we need to use the following filter:
*.*|*.svn-base all-wcprops entries format dir-prop-base

And the third way is a Bash command like this:
find ! -path "*_svn*" -exec cp --parents {} "../withoutsvn/" \;

Thank you for your attention and i hope this post was a bit helpful for you.

пятница, 29 января 2010 г.

Grep after grep

First of all bash scripts are realy cool. Last days they helped me many times in different situations.

Today i had the following task which i solved with bash script in a few lines of code.

On the remote machine i needed to find files which contained "phrase1" and at the same time not contained "phrase2". I didn't find a regular expression which could solve it in one Grep command, therefore i created two Grep commands using the output of the first Grep as input for the second Grep expression.

Finally, i wrote the following bash script:

#!/bin/bash
for i in `grep -r -l "phrase1" *`; do
if [ -f "$i" ]; then
grep -L "phrase2" "$i" >> log.txt
fi;
done

Just six lines of code. And it works )

Dear friend, i hope this post was helpful to you as it was for me.

P.S. Many thanks to Alexey Kirillov who helped me with this bash script. )