Tuesday, April 15, 2014

linux, find a line in a file and delete it, by using "sed"

 Q: need to grep for a particular 'string' in a file and remove the entire line where the occurrence of the string is found. I want it to work across with a collection of files. Can you help?
A:  It is possible to use grep for this: grep -v string file will output all lines that do not contain the string. But sed is a more suitable tool for batch editing.
sed --in-place '/some string/d' myfile
will delete all lines containing 'some string' To process a collection of files, you need to use a for loop (or find) because sed 's --in-place option only works on single files. One of these commands will do it:
for f in *.txt; do sed --in-place '/some string/d'
"$f"; done
find -name '*.txt' -exec sed --in-place=.bak '/some
string/d' "{}" ';'
Adding =.bak in the latter example makes sed save a backup of the original file before modifying it.

Saturday, April 5, 2014

VIM: Insert a string at the beginning of each line

This replaces the beginning of each line with "//":
:%s!^!//!
This replaces the beginning of each selected line (use visual mode to select) with "//":
:'<,'>s!^!//!
Refer:
http://stackoverflow.com/questions/253380/how-do-i-insert-text-at-beginning-of-a-multi-line-selection-in-vi-vim

Tuesday, April 1, 2014

setup Rsyslog and Mongodb on Centos 6.3

I did some modify and correct some errors from following  links.

The reference links:
1)http://loganalyzer.adiscon.com/articles/using-mongodb-with-rsyslog-and-loganalyzer
2http://wiki.rsyslog.com/index.php/HOWTO:_install_rsyslog_%2B_mongodb_%2B_loganalyzer_in_RHEL_6.2
3)http://wiki.rsyslog.com/index.php/Rsyslog_v6_configuration_example


//make sure that you install the EPEL source.
http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F



Install Apache + PHP:
----------------------
$yum install httpd php
$chkconfig httpd on
$service httpd start


Install Adiscon Loganalyzer:
-----------------------------
$yum install php-bcmath php-gd
Download, install and configure Adiscon Loganalyzer as documented in the INSTALL file to "/var/www/html". You can find the INSTALL file in the loganalyzer sources.
// cp all the folders and files from "/src" to "/var/www/html"


Install MongoDB:
----------------
$yum install mongodb mongodb-server php-pecl-mongo
$chkconfig mongod on
$service mongod start

Install the follow three packages with order: libestr -> libee -> liblognorm.
The reason why we need to build them from source is that we need to compile the Rsyslog by ourself.

Install libee, libestr, liblognorm:
------------------------------------
$yum install gcc make pkgconfig
Download, compile and install sources with:
$./configure --libdir=/usr/lib64/ --includedir=/usr/include --prefix=/usr
$make
$make install

Install libmongo-clientInstall libmongo-client:
------------------------------
$yum install git automake autoconf libtool glib2-devel
$git clone git://github.com/algernon/libmongo-client.git
$cd libmongo-client
$./autogen.sh
$./configure --libdir=/usr/lib64/ --includedir=/usr/include --prefix=/usr
$make
$make install
you may need following packages:
yum install json-c-devel libuuid libuuid-devel 

Install rsyslog:

yum install rsyslog-mongodb


manage Latex package manually on ubuntu

1. ubuntu doesn't support Latex automatic package system. they suggest you to manage package manually.
http://tex.stackexchange.com/questions/73116/fresh-install-texlive-2012-ubuntu-12-04-tlmgr-nowhere-to-be-found

2) here is the instruction for Manual management.
Installing packages manually
If a package you desire is not in Ubuntu's repositories, you may look on CTAN's web site or TeX Catalogue Online to see if they have the package. If they do, download the archive containing the files. In this example, we'll install example package foo, contained in foo.tar.gz.

Once foo.tar.gz has finished downloading, we unzip it somewhere in our home directory:


tar xvf foo.tar.gz
This expands to folder foo/. We cd into foo/ and see foo.ins. We now run LaTeX on the file:


latex foo.ins
This will generate foo.sty. We now have to copy this file into the correct location. This can be done in two ways. After these, you can use your new package in your LaTeX document by inserting \usepackage{foo} in the preamble.

User install

We will copy this into our personal texmf tree. The advantages of this solution are that if we migrate our files to a new computer, we will remember to take our texmf tree with us, resulting in keeping the same packages we had. The disadvantages are that if multiple users want to use the same packages, the tree will have to be copied to each user's home folder.

We'll first create the necessary directory structure:


cd ~
mkdir -p texmf/tex/latex/foo
Notice that the final directory created is labeled foo. It is a good idea to name directories after the packages they contain. The -p attribute to mkdir tells it to create all the necessary directories, since they don't exist. Now, using either the terminal, or the file manager, copy foo.sty into the directory labeled foo.

Now, we must make LaTeX recognize the new package:


texhash ~/texmf
System install

We will copy the foo to the LaTeX system tree. The advantages are that every user on the computer can access these files. The disadvantages are, that the method uses superuser privileges, and in a possible reformat/reinstall you have to repeat the procedure.

First, go to the folder your foo is located. The following commands will create a new directory for your files and copy it to the new folder:


sudo mkdir /usr/share/texmf/tex/latex/foo
sudo cp foo.sty /usr/share/texmf/tex/latex/foo
Then update the LaTeX package cache:


sudo texhash