def worker(queue):     while True:         if not queue.empty():             words = 'BananA'             words1 = 'nut'             words2 = 'KreMA'             words3 = 'KIVI'             words4 = 'TesT'             process(data, words, words1, words2, words3, words4)  def process(data, words, words1, words2, words3, words4):     if (search != words):         print("Words Not Found")     if (words in search or words1 in search or words2 in search or words3 in search or words4 in search):         print("Words Found  : " + str(Words) + "\n")         file = open("finded.txt","a")         file.write("Words Founds "+ str(words)         file.close()   but, if change the line if "banana"  to "Banana"  the code not work, I need Banana or BANANA or BaNaNa get equal, and get true,
2821
How can I do case insensitive string comparison in Python?  I would like to encapsulate comparison of a regular strings to a repository string using in a very simple and Pythonic way. I also would like to have ability to look up values in a dict hashed by strings using regular python strings.
30785
I'm trying to build a command line tool to look up definitions of words, it's only a dummy app for me to practise my C++ skills.  I know there is a list of words stored at /usr/share/dict - but what I'm really looking for is the path to the New Oxford American Dictionary data, it comes bundled with the system, but I couldn't find it yet.
95856
I have some Python code that works correctly when I use python.exe to run it, but fails if I use pythonw.exe.       def runStuff(commandLine):         outputFileName = 'somefile.txt'         outputFile = open(outputFileName, "w")          try:             result = subprocess.call(commandLine, shell=True, stdout=outputFile)         except:             print 'Exception thrown:', str(sys.exc_info()[1])      myThread = threading.Thread(None, target=runStuff, commandLine=['whatever...'])     myThread.start()   The message I get is:       Exception thrown: [Error 6] The handle is invalid   However, if I don't specify the 'stdout' parameter, subprocess.call() starts okay.  I can see that pythonw.exe might be redirecting output itself, but I can't see why I'm blocked from specifying stdout for a new thread.
11923
I'm trying to split a string up into words and punctuation, adding the punctuation to the list produced by the split.  For instance:  &gt;&gt;&gt; c = "help, me" &gt;&gt;&gt; print c.split() ['help,', 'me']   What I really want the list to look like is:  ['help', ',', 'me']   So, I want the string split at whitespace with the punctuation split from the words.  I've tried to parse the string first and then run the split:  &gt;&gt;&gt; for character in c: ...     if character in ".,;!?": ...             outputCharacter = " %s" % character ...     else: ...             outputCharacter = character ...     separatedPunctuation += outputCharacter &gt;&gt;&gt; print separatedPunctuation help , me &gt;&gt;&gt; print separatedPunctuation.split() ['help', ',', 'me']   This produces the result I want, but is painfully slow on large files.  Is there a way to do this more efficiently?
81623
I am writing a script, I want to check if the first line of the file matches a certain pattern and if it does then print out the file. How can I achieve this?  How do I check for pattern? Is there a way to check for pattern and based on the output do something..  EDIT: Please take a look at this question:   I want something like this, but none of them worked for me. I basically want to check if the first line matches a regex pattern or not and based on that print the lines of file.
71907
I have a .txt file with 5 urls in it. I want to read it line by line, and perform 4 ping requests for each site, and extract the time. The code I wrote is below, but it isn't working.   Can anyone give me a hint?   #!/bin/bash  cat /home/akis/Desktop/sites.txt declare -i var=1 while read -r line do     while $var &lt;= 5      do         var2=$((var2+1))          name="$line" | ping -c 4 $name &gt; $var.txt | awk '{ print $8 }' &lt; $var.txt | awk '/time/' &gt; $var2.txt | tr '=' '\t' &lt; $var2.txt | awk '{ print $2 }' &gt; $var2.txt     done      var=$((var+1))   done
80769
Lets say I'm doing a database for fruits. Using a text file for it, inside contains, in this format,  (Fruit:Quantity:Cost) Apple:10:1 Orange:20:2 Pears:10:3 Banana:20:4  10 Apples at $1 each. 20 Oranges at $2 each. 10 Pears at $3 each. 20 Bananas at $4 each.   My simple script goes like this:  echo "Enter fruit to find" read fruit  echo "Enter quantity to find" read count  echo "Enter cost to find" read cost  grep $fruit FruitDB.txt     It will display the fruits in the database.  But how do i use grep and cut together to find just by the quantity or the cost. In the quantity count area, let's say i enter 20, it will display the Oranges and Banana. Or when i enter count and cost, it will display just those that meet the conditions.
102970
I am currently facing a "performance problem" while using grep. I am trying to locate the occurrences of many (10,000+) keywords in many (think Linux kernel repository size) files. The objective is to generate a kind of index for each keyword:   keyword: my_keyword filepath 1 filepath 2 ------ keyword: my_keyword2 ...   Being fairly new to shell scripting, I have tried a few naive approaches:  while read LINE; do     echo "keyword: "$LINE &gt;&gt; $OUTPUT_FILE     grep -E -r --include='Makefile*' "($LINE)" . &gt;&gt; "$OUTPUT_FILE"     echo "-----" done &lt; $KEYWORD_FILE   This takes about 45 minutes to complete, with the expected results.  Note: all they keywords I search for are located in a file ("KEYWORD_FILE", so fixed before anything starts), and the files in which to search can be determined before the search starts. I tried to stored the list of files to search in before the search like that:  file_set=( $(find . -name "Kbuild*" -o -name "Makefile*") )   and then replace the grep call by  echo {$file_set[*]} | parallel -k -j+0 -n 1000 -m grep -H -l -w "\($LINE\)" &gt;&gt; "$OUTPUT_FILE"   It takes about an hour to complete&hellip;  Question: considering I can use whatever technique I want, provided it's sh compliant, how can this be done "faster" and/or more efficiently ?  Perhaps grep is not the tool to use, and my use of parallel is wrong&hellip; any ideas are welcome!
38090
I am trying to write an if statement to test whether there are any files matching a certain pattern. If there is a text file in a directory it should run a given script.  My code currently:  if [ -f /*.txt ]; then ./script fi   Please give some ideas; I only want to run the script if there is a .txt in the directory.
94270
The command that I have prints out two of the lines whenever FW_6.0.0 is found, below is the code:  grep -oP 'FW_6.0.0, (.*)$' file   Below is the output, both has the same value of FW_6.0.0  FW_6.0.0, SUCCESS FW_6.0.0, OK   I would like to match two words, that is FW_6.0.0 and SUCCESS that can be found on the same line so that it prints this out:  FW_6.0.0, SUCCESS and eliminates FW_6.0.0, OK
46377
While dabbling in Clojure I've written a very basic program to echo whatever the user types into it. However, it doesn't run in a way that I'm perceiving to be natural. Here's the code:  (defn goo []   (print "echo&gt; ")   (def resp (read-line))   (print resp) )   I would expect the code to run like this (for me typing in foo as the input to read-line):  user=&gt; (goo) echo&gt; foo foonil   But instead, the echo and read-line is switched:  user=&gt; (goo) foo echo&gt; foonil   Why does this happen? Is there a subtlety I'm missing?  EDIT: From Joe's answer, the updated correct solution is:  (defn goo []   (print "echo&gt; ")   (flush)   (def resp (read-line))   (print resp)   (flush) )   Also, the flushes aren't necessary if you use println instead of print.
101762
I have two files in these formats:   file1 :  air smell hand dude road cat   file 2:   air,4,21,01,13,3,2 smell,21,4,2,5,6 dude,1,31,42,1 road,1,4,2,1,4 cat,1,5,6,3,1 hand,1,4,2,1,6 mouse,1,3,5,6,2   what I want to do is print the entire row of file 2, if the first string in column 1 of file 2 is found in file 1, and I want to keep the order of file 1.   expected output:   air,4,21,01,13,3,2 smell,21,4,2,5,6 hand,1,4,2,1,6 dude,1,31,42,1 road,1,4,2,1,4 cat,1,5,6,3,1
45219
There are a couple of times I have been presented with some codes as solutions to problems. My question is how do write these type of scripts myself for some fairly routine tasks?
42087
Writing a python script and it needs to find out what language a block of code is written in. I could easily write this myself, but I'd like to know if a solution already exists.  Pygments is insufficient and unreliable.
1704
This has always confused me. It seems like this would be nicer:  my_list = ["Hello", "world"] print(my_list.join("-")) # Produce: "Hello-world"   Than this:  my_list = ["Hello", "world"] print("-".join(my_list)) # Produce: "Hello-world"   Is there a specific reason it is like this?
40125
Take the following sentence:     And even if the program inputted one token and then invoked newLine(), wouldn't it input a blank?   I've been told that this sentence has a clear pronoun reference. Why? Couldn't it refer to either program or token?
58499
I have a large JSON file that is on one line, and I want to use the command line to be able to count the number of occurrences of a word in the file. How can I do that?