- Strength to Increase Rep
- +8
- Strength to Decrease Rep
- -2
- Upvotes Received
- 10
- Posts with Upvotes
- 10
- Upvoting Members
- 7
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
123 Posted Topics
Re: [QUOTE=a1eio;332281]yea, i forgot to mention, i'm trying to do this on a windows machine. the os.popen idea did occur to me, but then i got stuck again.. :p i don't know the dos command for opening the cd drive. thanks a1eio[/QUOTE] if you have pygame, you can use its inbuilt … | |
Re: [QUOTE=Ene Uran;249919]If anyone figures out a different way to sort by word length....[/QUOTE] [code] >>> list1 = ['Herring','used','to','be','abundant','in','the','Atlantic','Ocean','then','herring','got','overfished'] >>> lengthlist = map(len,list1) >>> lengthlist [7, 4, 2, 2, 8, 2, 3, 8, 5, 4, 7, 3, 10] >>> all = zip(lengthlist,list1) >>> all [(7, 'Herring'), (4, 'used'), (2, 'to'), (2, … | |
Re: [QUOTE=Lardmeister;334753]When I run: [code]dec = 255 print hex(dec) [/code]I get 0xff, but I like to get just 'ff'[/QUOTE] '0x' always appears in front, so if you want to use hex() and get rid of 0x, use hex(255)[2:] | |
Re: [QUOTE=chris99;253120] [code] def prompt_rea(): global gold .... .... [/code] Can you see the problem?[/QUOTE] if you want to use gold as global, u might like to put "global gold" inside prompt_rea() | |
Re: [QUOTE=sneekula;317313]I need to read in a text file, replace selected words and write the changed text back out to a file. Is there an easy way with Python?[/QUOTE] there are several ways. 1) reading with for loop [code] o = open("output","a") #open for append for line in open("file"): line = … | |
Re: [QUOTE=sneekula;318529]Is there a reliable way to 'pluralize' english words with Python?[/QUOTE] there are some cookbook recipe in ASPN you can refer to. [URL="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82102"]here[/URL]. they may not be wat you want, but at least will give you a head start | |
Re: you do it systematically using the same way to read single level dict [code]d={'AAA': {'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'}, 'BBB': {'BBB1':{'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'}, 'BBB2':{'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'}, 'BBB3':{'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'}}} for i,j in d.iteritems(): for m,n in j.iteritems(): print m,n [/code] … | |
Re: things can be that easy. [code] $string = "<TEXT> Some text Another text </TEXT>"; @s=split /<\/TEXT>/, $string; $s[0] =~ s/.*<TEXT>// ; print $s[0]; [/code] | |
Re: >>> a = 'nf+nfpermult+nf' >>> a=a.split("+") >>> for n,i in enumerate( a ): ... if i == "nf": a[n]="1.0" ... >>> print '+'.join(a) 1.0+nfpermult+1.0 | |
Re: you are using the "wrong" approach to reading a file. use a for loop [CODE] f=open("file") for line in f: print "do something with ",line f.close()[/CODE] | |
Re: use a html parser for this job, such as BeautifulSoup. If you don't want to, then another way is to read the whole html, split on "</div>", go through each element in the list, check for "<div class="info-content">", if found, replace it will null. You will get your string | |
Re: no need to use regex 1) split on "</a>" 2) go through list, check of List?ratings. 3) get index of ">, 4) print [code] >>> string = '''<a href="/ratings_explained">weighted average</a> vote of <a href="/List?ratings=7">7.2</a> / 10</p><p>''' >>> for i in string.split("</a>"): ... if "List?ratings" in i: ... print i[ i.rindex('">')+2 … | |
Re: it depends on what errors you are looking for. If there are 1000s of errors, are you going to send all 1000 ++ errors to your email?? you have to describe clearly your specs. | |
Re: you can use splitext from os module [code] import os,shutil def renamer(target) : os.chdir(target) for filename in os.listdir('.') : print filename newfilename = os.path.splitext(filename)[0] print newfilename os.rename(filename, newfilename) print "Renamed " + filename + " to " + new_filename shutil.copy("copyme","newcopyme" [/code] | |
Re: use awk [code] awk '/default = ALL/{ print "default = DES-168" print "default = RC2-128" print "default = RC4-128" print "#"$0 next}1' file [/code] | |
Re: [code] # perl -ne 'print if !(/\[SectionOne\]/ .. /\[SectionTWO\]/); ' file Entry1=19 Entry2=hello there [/code] use module like Config::IniFiles is still the best. | |
Re: you can learn the basics of Perl first. One of the many good sources is straight from the doc. type perldoc perl for more info. otherwise, you can always view online Perl doc with your browser. After you are proficient with it, you can play with web frameworks, such as … | |
Re: i think you shouldn't need to worry too much on whether its the correct directory because you would have set it properly when configuring your FTP server. | |
Re: if you have Perl, you can use the MP3::Tag module. eg [code] use MP3::Tag; # set filename of MP3 track my $filename = "test.mp3"; # create new MP3-Tag object my $mp3 = MP3::Tag->new($filename); # get tag information my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo(); print "$title, $track, … | |
Re: regular expressions are usually not needed for string manipulations. [code] # echo "abcdd" | awk 'BEGIN{FS=""}$2==$3{print "ok"}' # echo "abbdd" | awk 'BEGIN{FS=""}$2==$3{print "ok"}' ok [/code] | |
Re: [code] awk '{printf "%s %s",$0, ($3 > 40)? "yes" :"no"}' file [/code] | |
Re: [QUOTE=pinder;343621]Hi, I'm trying to copy a file in python, I have imported the shutil module My problem is that I want to copy file in a directory beginning with a certain name. Example I have 5 file in the fodler but i want to copy all the one tat begin … | |
Re: [code] awk 'BEGIN{FS="[]].[[]|[[]|[]]"} { gsub(/id|\"/,"",$13) split($3,a,"/") gsub("tag","",$16) print $13,a[1],$7,$16 }' file [/code] | |
Re: without glob module, just search for it [code] import os os.chdir("/somewhere") for files in os.listdir("."): if not "_ab" in files: print files [/code] | |
Re: [QUOTE=bimaljr;689099]Hi, I just need to know a simple command to bulk renaming. I have hundreds of .DEB files. I want to remove [B]4%3a[/B] from all file names. [B]example :[/B] [I]old name :[/I] ark-kde4_4%3a4.0.3-0ubuntu4_i386.deb [I]new name :[/I] ark-kde4_4.0.3-0ubuntu4_i386.deb I know there is a "rename" command but I don't know it's use. … | |
Re: [QUOTE=Gromit;686845]I poked at your original script and made some syntax changes to your "if" statement. I think it does what you want now. I think you have to use brackets when doing a comparison like this: [code] $ cat daniweb.sh #!/usr/bin/bash memUsage=$(ps -C bash -o pid=,size|awk '{SUM += $2} END … | |
Re: better still, no need grep [code] top | awk '/root/{ sum += $10 }END {print sum}' [/code] | |
Re: Look at the bash guide [URL="http://tldp.org/LDP/abs/html/testbranch.html"]here[/URL]. It has examples on checking for upper case. | |
Re: sed will be slower than tail for huge files. Just a tip | |
Re: [code] awk 'BEGIN{FS="[: ]"} /Name/{ name=$3 } /Active/ && /Yes/{ cmd = "mailx -s \""name " is active\" body root" system(cmd) } ' file [/code] | |
Re: do it using awk's srand() and rand(). [code] awk 'BEGIN{ srand() num=int(rand() * 10) + 1 } NR==num' file [/code] | |
Re: if TEST2 is the second field and no where else and you want to replace only that second field, [code] awk 'NR==4{$2="DEV"}1' file [/code] | |
Re: [QUOTE=k2k;620065]can anyone tell me how I can print the first or the last character from a sh file ? i have done research on regular expression and the grep... i couldn't find any cmd that i can use to achieve this task. Thanks a lot.[/QUOTE] [code] awk 'BEGIN{FS=""}NR==1{print $1}{l=$NF}END{print l}' … | |
Re: [QUOTE=Anilbrp]Hi all, I am new to this perl script. I want to open notepad.exe in perl script in the foreground., i.e if I give the command as system ("c:\\windows\\notepad.exe") , notepad should appear in the foreground. (should not run as a background process). I am using Apache server on windows. … | |
Re: [QUOTE=wandie;358984]Could someone please help. I would like to sort a multidimensional array. But to sort it out by one key which appears in all array for example. [code] total=[[serial,'john'],[[serial,'james']] [/code] all the records i have all in arrays they contain a "serial" i would like sort by serial. I have … | |
Re: [QUOTE=skelly16;584443]Ok the issue i have worked out is when there seems to be a space on the new line on the file. i.e. cat apps/tech/testruniquefailures <space is here> batchjob1 batchjob2 How do i make sure the above file does not have a space on the top of it.[/QUOTE] don't use … | |
| |
Re: what have you learnt in that online class so far? do you have lecture notes and books for shell scripting? | |
Re: [QUOTE=paurik;580658]Hi i m devloping one intratnet appllication for that i want some hardwre information like memory type,memory bank, BIOS information. I have no rights login as super user. if anybody has any idea for that plese give me reply.[/QUOTE] if you are really developing an intranet application, then ask the … | |
Re: [code] awk '$NF <=3 {a[NR]=$NF;c[a[NR]]=$0} END{ n=asort(a,b) print c[b[n]] }' file [/code] output: [code] # ./test.sh 18 126 2833 30 0.010479 2.842 [/code] | |
Re: use the -v option of awk to pass in shell variables so that you don't have to get too confused between shell and awk variables. eg [code] awk -v archive="$ARCHIVE" ' { print archive # etc code } [/code] also you do not need to use ls , grep and … | |
Re: no need to use cat [code] uuencode $file $file | /usr/bin/mailx -s "TEST" [/code] | |
Re: simply assign to a variable first [code] cmd = "useradd -G " var1 " -g " var2 " -m -s " $1 " -u " $2 " -K PASS_MIN_LEN=4 -K PASS_MAX_LEN=7 -p \047*\047" "usrname" print cmd # to see if your cmd is correct system(cmd) [/code] | |
Re: [QUOTE=alex05;163184]I have to write a script called trying. The script takes a full path (like /users4/st/jdoe/prog.c) as an argument and displays the path and the file name. For /users4/st/jdoe/prog.c, the path is /users4/st/jdoe and the file name is prog.c. I know that I can use grep for it, but it's … | |
Re: [code] awk 'NR==1{ print "var="$1}' file [/code] | |
Re: [code] # echo $HTML | sed 's/<html><body>\(.*\)<\/body><\/html>/\1/' OK [/code] | |
Re: [QUOTE=binnie;509555]I would like to ask for the looping statements and conditional statements syntax and some samples for me to easily understand... And also, How can I edit numbers to have its decimal points like float and double in other programming language. I'm really noobie with Linux so can someone please … | |
Re: [QUOTE=eggi;457585]#!/bin/ksh cat inputfile.txt|while read v w x do if [ -e $x ] then num_lines=`wc -l $x|sed -e 's/ *//' -e 's/ .*$//'` time_stamp=`ls -l $x|awk '{print $6 "_" $7 "_" $8}'` echo "$v $w $x $num_lines $time_stamp" fi done [/QUOTE] no need for cat [code] while read .... do … | |
Re: [code] find /path -type f -name "status10.dat*" -mtime 0 -print0 | xargs -i -0 cp "{}" /cerner/d_p19/ccluserdir [/code] |
The End.