Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Sep 172010
 

Multiple separators in awk

Answer:

Sometimes when you split a string using awk, you need to support more than 1 separators, you can use the -F option.

E.g.

# cat foo.txt | awk -F "[ ?]" '{print $7}'

Now the awk split by a space and by a ?.

Sep 142010
 

Calculate PHP script's execution time

Answer:

If you want to estimate the PHP script's execution time, you can try something like the following:

<?php

$time_start = microtime(true);

// some long running codes...

$time_end = microtime(true);

echo "Time (msec) passed: " , $time_end - $time_start;
Sep 132010
 

How to set the filetype in Vim

Answer:

When you created a new file by using the command vi, vim does not know the file type unless you save the file with a specific extension, e.g. test.c, or sometimes when the extension cannot be recognized by vim, you need to set the file type manually in command mode - pressing Esc + :

:set filetype=c

That is it.

Sep 112010
 

Multi-line strings in Bash

Answer:

Bash support multiple line string, e.g.

#!/bin/bash
sort  <<EOT
apple
orange
banna
EOT

When you execute the script,

# bash test.sh

It gives:

apple
banna
orange