Write Python script using utf-8
Answer:
If you have UTF-8 characters in your Python script, you need to declare the following line at the beginning of your script:
# -*- coding: utf-8 -*-
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Write Python script using utf-8
Answer:
If you have UTF-8 characters in your Python script, you need to declare the following line at the beginning of your script:
# -*- coding: utf-8 -*-
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 ?.
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;
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.
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