How to print a file by line range using sed?
Answer:
In a given file, if you want to print out, say line 340-350, is easy with sed:
# sed -n '340,350p' text.txt
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
How to print a file by line range using sed?
Answer:
In a given file, if you want to print out, say line 340-350, is easy with sed:
# sed -n '340,350p' text.txt
Remove specified lines from a file using sed
Answer:
Assume your have a file text.txt contains 100 lines, if you want to remove the lines 20-30, what you need is sed:
# sed '20,30d' text.txt
That's is easy.
What is the file dead.letter in my home folder?
Answer:
The file dead.letter is usually created by mail client such as /usr/bin/mail, when you abort the message being sent, a copy of the message will be saved in your home folder: dead.letter.
Character classes not working in grep command
Seems grep / egrep does not support character classes, e.g.
# find -type f | grep -e '[\d]'
It finds all the file contains the character d, instead of decimal number(s).
Answer:
By default, egrep only understand the POSIX Basic Regular Expressions (BRE) standard, so what would like to use is:
# find -type f | grep -e '[[:digit:]]'
or you can force to interpret as a Perl regular expression
# find -type f | grep -P -e '[\d]'
Strict comparison in PHP
Answer:
PHP has two ways to compare two variables, type-safe and type-less, e.g.
Type-safe
print ( "123" === "123" ); // print 1
print ( 123 === 123 ); // print 1
print ( 123 === "123" ); // print nothing
Type-less
print ( "123" == "123" ); // print 1
print ( 123 == 123 ); // print 1
print ( 123 == "123" ); // print 1
Reference: http://php.net/manual/en/language.operators.comparison.php