Skip to content

Tag: if-statement

using for in loop with sql output

I have a roles.txt file that contains SELECT ROLE_NAME FROM SENTRY_ROLE WHERE ROLE_NAME produces: Im trying to echo all the roles from roles.txt that are not in the sql_output (user in this example). This is what i have so far: Answer That’s not how you iterate over the lines of a file. See http://mywik…

Bash: if statement always succeeding

I have the following if statement to check if a service, newrelic-daemon in this case, is running… The problem is it’s always returning as true, i.e. “New Relic is already running”. Even though when I run the if condition separately… … it returns 0. I expect it to do nothin…

move single string up into previous row

I have been trying to solve a problem for hours and haven’t found a solution. I am trying to reformat a text file that has been incorrectly parsed. The file format contains a list of names, starting with the last name first, and has a troublesome sole first name on one of the rows as below: I have tried…

Syntax error at or near {

I have an assigment where I have to count the number of words in each .c .cc and .h file.The problem is it keeps showing the syntax error at line 8 and 10 at or near { .This is not a finished script!It may have some other problems but I only needed help with the syntax error! Answer Inside an

If a File is Empty, Write Text to First Line

I need to check to see if two files are empty. If they are, then write “-999” to the file, else run an average on the numbers within the file. Here is the coding I’ve been trying to use: Code: Contents of file_all: Answer the appropriate way to check whether a file is empty is using -s not -…

execute code only while sys.argv[1] exist

I have this code: and i want execute this piece of code only while sys.argv[1] is exist: if i only start the program without an arguments (python program.py) it’s print this text: I tried “if sys.argv == 1” but doesnt worked. Any solutions? Thanks Answer Now your program will terminate entir…