Dong's bloglife

share computer knowlege with everyone!

  • Home
  • Sample Page
RSS

Increase or decrease characters at the begin or end of line with sed

Posted on 2011/12/31 by dgfsummit
No comments

In the use of Linux, we are often increase or decrease the characters at the begin or end of line in the document, but if the document is too large, and more cumbersome manual changes, you can use sed to modify batch.
Add a character at the begin of each line

1
sed -i 's/\(^\)/#/g' /home/test.txt #add a '#' at the begin of line
1
sed -i 's/\(^.\)/#/g' /home/test.txt #instead of the first character

Delete the character of ‘#’

1
sed -i 's/#/ /g' /home/test.txt

Add a string at the end of line

1
sed -i 's/\($\)/aaa/g' /home/test.txt #add a string of 'aaa' at the end of line
Categories: shell | Tags: bash, begin, end, sed, shell

Compare time with python

Posted on 2011/12/27 by dgfsummit
No comments

1.Get the time of month and year

1
2
3
4
5
6
7
8
get the time of last month
time.localtime()[1]-1
 
get the time of last year
time.localtime()[0]-1
 
get the time of two months later
time.localtime()[1]+2

Read more …

Categories: python | Tags: compare time, datetime, python, time

get time with python

Posted on 2011/12/27 by dgfsummit
No comments

There is a time module available in Python which provides functions for working with times, and for converting between representations. The function time.time() returns the current system time in ticks since 12:00am, January 1, 1970.
1.get the seconds from 1970-01-01 00:00:00

1
2
3
4
#!/usr/bin/python
import time
NumTime = time.time()
print "Seconds of from 1970-01-01 00:00:00 is:",NumTime

Read more …

Categories: python | Tags: date, python, time
  • Recent Posts

    • Increase or decrease characters at the begin or end of line with sed
    • Compare time with python
    • get time with python
  • Recent Comments

    • Categories

      • python
      • shell
    • Archives

      • December 2011 (3)
    © Dong's bloglife. Proudly Powered by WordPress | Nest Theme by YChong