Partially used Python code

Source: Internet
Author: User

1 Replace file extensions2 #Change . htm files to. html3  forFileinch*.htm; Do MV $file ' echo $file | Sed's/\ (. *\.\) htm/\1html/''; done4 #Change . html files to. htm5  forFileinch*.html; Do MV $file ' echo $file | Sed's/\ (. *\.\) html/\1htm/''; done6 #Change . html files to. shtml7  forFileinch*.html; Do MV $file ' echo $file | Sed's/\ (. *\.\) html/\1shtml/''; done8 #Change . html Files to php9  forFileinch*.html; Do MV $file ' echo $file | Sed's/\ (. *\.\) html/\1php/''; doneTen  OneReplace stringinchtext A:%s/str1/str2/GC Entire Document -: 1, $s/str1/str2/GC Entire Document -:., $s/str1/str2/GC from current to end the  - #extract a range of lines from a text -Sed-n 16224,16482p filename >NewFile -Sed-n-e 12345p filename >NewFile +Sed'5!d'FileName >NewFile -  + #Compare substring of a field AAwk'{if (substr ($1,0,7) >6435201 && substr ($1,0,7) <6521605) print $}' at  - #Find a file -Find./-name'my*' - #Find & CP -Find/path/to/your/files-name name. EXT-execCP-RFP {}/dst_dir \; -  in  - #add numbers in a bash script tonum=$ ((NUM1 +num2)) +num=$ (($num 1 + $num 2))#also works -num=$ ((NUM1 + 2 + 3))# ... theNUM=$[NUM1+NUM2]#Old , deprecated arithmetic expression syntax *  $ Panax Notoginseng #Assign Output of Shell Command to Variable -var=$ (command-name-Here ) thevar=$ (command-name-Here arg1) +var=$ (/path/to/command) Avar=$ (/path/to/command arg1 arg2) theVar= ' command-name-Here ' +Var= ' command-name-Here arg1 ' -Var= '/path/to/Command ' $Var= '/path/to/command arg1 arg2 ' $  - #Fg/bg/nohup -Find/etc/httpd/-name"httpd.conf"-Print>find.dt 2>&1 & the  -Awk'{if ($11== "9002" && $6==0) {revenue+=$3;count++}}end{print revenue;print count}'new_ck_tableWuyiAwk'{if ($3== "+1") count++;} End{print count;}'file.txt theAwk'fnr==nr{a[$1]=1; next}; {if ($ in a) print $}'Rank02.dat 0201-all.tmp3 >Rank02.tmp3 -  Wu #output third column to end of each row -Cut-d":"-F 3- About #Filter Empty lines $Grep-e'^$'-v -  - #comment/uncomment -CTRL + Vx ACtrl + V Shift+i#ESC +  the #sort by one column -Sort-k 1 0316.new-o 0316. New $  the #Remove Leading space theSed-e's/^[\t]*//' the  the #Mount NFS -Mount-t NFS 10.134.12.60:/data/online/Public Localdir in  the  the ##---------------High frequency python command------------------------ About  the #Regex the  theText ="<H1>title</H1>" +RE.MATHC ('<.*>', text)#Match <H1>title</H1> -Re.match ('<.*?>', text)#Match <H1> the Bayi  the  the #sum of elements in a list -sum = reduce (Lambdax,y:x+y, MyList) -  the #Compare all elements in and lists the ifAll (x==y forX, yinchZip (X, Y)) the Do something the  -      the #get sorted dictionary by key the Sorted (Dd.keys ()) the[(Key, Dd[key]) forKeyinchSorted (Dd.keys ())]94 Print ' '. join ([STR (key) +':'+str (Dd[key]) forKeyinchSorted (Dd.keys ())) the  the      the #get sorted dictionary by value98[Key forKeyinchSorted (DD, Key=dd.get, reverse=True)] About[(Key, Dd[key]) forKeyinchSorted (DD, Key=dd.get, reverse=True)] - Print ' '. join ([STR (key) +':'+str (Dd[key]) forKeyinchSorted (DD, Key=dd.get, reverse=True)])101Sorted (Mydict.items (), key=LambdaE:E[1][2])#value is a list102 103 #get key intersection of dictionaries104intersect = Set (Dict_a.keys ()) &Set (Dict_b.keys ()) the 106 #sort a list of tuples107Sorted_list = sorted (tuples, key=Lambdax:x[0])108 109 #map list onto dictionary theMydict = {X.split (':') [0]:x.split (':') [1] forXinchMyList}111  the  fromOs.pathImportbasename113  fromOs.pathImportSplitext theFName =Splitext (basename (fullname)) [0] the  the #sort list and return index of list117Sorted_index = sorted (range (Len list), key=LambdaK:list[k])118 119 #intersection of Lists -B1 = [...]121B2 = [...]122intersection =Set (B1). Intersection (B2)123 124 #string to Date/date to string the Importdatetime126Obj_date = Datetime.datetime.strptime (Str_date,"%y%m%d%h%m"). Date ()127Str_date = Obj_date.strftime ('%y%m%d%h%m') -Obj_date = obj_date + Datetime.timedelta (days=-1)129 #Date to timestamp theTime.mktime (Time.strptime ('2015-03-15 00:00:00','%y-%m-%d%h:%m:%s'))131  the #Read first N line of a file133With open ("datafile") as MyFile:134Head = [Next (myfile) forXinchxrange (N)]135 PrintHead

Partially used Python code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.