Grep

Categories: Linux; Tagged with: ; @ May 8th, 2014 21:50

guoliang@GDEV /tmp $ grep ‘hi’ test1.txt
hi
hihihihi

# Display line number
guoliang@GDEV /tmp $ grep -n ‘hi’ test1.txt
3: hi
4:hihihihi

# Count
guoliang@GDEV /tmp $ grep -c ‘hi’ test1.txt
2

# Case insensitive
guoliang@GDEV /tmp $ grep -n -i ‘hi’ test1.txt
1: HI
2: Hi
3: hi
4:hihihihi

# Search the whole word
guoliang@GDEV /tmp $ grep -n -w ‘hi’ test1.txt
3: hi

# Search recursively
guoliang@GDEV /tmp $ grep -n -w ‘hi’ -r  test*
test1.txt:3: hi
test3:2:hi

# Use grep in Pipes
GDEV tmp # find . -name ‘test*’ |xargs grep ‘hi’
./test1.txt: hi
./test1.txt:hihihihi
./test2:Hi, this is test2;
./test3:this is test 3
./test3:hi

Linux Mint: Modify JAVA HOME for All Users

Categories: Linux; Tagged with: ; @ April 27th, 2014 12:14

Solution A:  Modify /usr/bin/java link

# which java
/usr/bin/java
# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.12) (7u25-2.3.12-4ubuntu3)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
# ls -ld /usr/bin/java
lrwxrwxrwx 1 root root 22 Apr 16 21:47 /usr/bin/java -> /etc/alternatives/java
# rm /usr/bin/java
# ln -s /guoliangDev/tools/sun-jdk/jdk1.7.0_55/bin/java /usr/bin/java
# java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

Solution B: Modify /etc/profile

#vi /etc/profile

Append:

export JAVA_HOME=/guoliangDev/tools/sun-jdk/jdk1.7.0_55
export PATH=$JAVA_HOME/bin:$PATH

save the file, and

source /etc/proflie

Python: String split and for each

Categories: Python; Tagged with: ; @ April 23rd, 2014 0:49

This example shows how to split string and do for…each in Python:

>>> rawTags = 'TAG1 TAG2 TAG3 TAGB1 TAGB2'
>>> tags = rawTags.split()
>>> tags
['TAG1', 'TAG2', 'TAG3', 'TAGB1', 'TAGB2']
>>> output = ''
>>> for tag in tags:
... output += '"' + tag + '",'
>>> output
'"TAG1","TAG2","TAG3","TAGB1","TAGB2",'

Python: Parse HTML using Beautiful Soup

Categories: Python; Tagged with: ; @ April 6th, 2014 17:24

Requirement:

Get the FX rate from: http://fx.cmbchina.com/hq

Solution:

Use urllib2 to get the html, use BeautifulSoup to parse the html;

Details:

1.  Get html by urllib2:

import urllib2
html = urllib2.urlopen(“
http://fx.cmbchina.com/hq”).read()

2. parse the html using BeautifulSoup:

install it:

$ apt-get install python-bs4 // http://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-beautiful-soup

Python Code:

from bs4 import BeautifulSoup
soup = BeautifulSoup(html)   # you may check the HTML by: print(soup.prettify()) 
sgRateString = soup.find(id=”realRateInfo”).find_all(‘tr’)[8].find_all(‘td’)[5].get_text()
sgRate = float(sgRateString)
print ‘SG Rate:’, sgRate

All Code:

Links

urllib2 examples:  https://docs.python.org/2/library/urllib2.html#examples

BeautifulSoup Quick Start: http://www.crummy.com/software/BeautifulSoup/bs4/doc/#quick-start

Using aMule to download eMule/ED2K in Linux/ubuntu/Mint

Categories: Linux分享; Tagged with: ; @ March 30th, 2014 21:23

Get a web UI to download ed2k link by following post:

http://ubuntuforums.org/showthread.php?t=327414&s=f1e51c3c8c7ceedfaecac02d8615063b

 

Cannot connect to the Server or Server list is empty:

Get the server.met from: http://www.gruk.org/list.php, replace your server.met;

 

SNAGHTMLa28393

Newer Posts <-> Older Posts



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.