finding string in file

All

Script to find string in file

To run in a directory:

fdemeloj@fdemeloj directory]$ for f in *; do python python_string.py  $f; done

import sys

def find(file, string_search):
with open(file) as myfile:
if string_search in myfile.read():
return True
return False

def find_line(file, string_search):
print(“XXXX”)
import re
errors = []
linenum = 0
pattern = re.compile(r””+string_search)
with open (file, ‘rt’) as myfile:
for line in myfile:
linenum += 1
if pattern.search(line) != None: # If pattern search finds a match,
errors.append((linenum, line.rstrip(‘\n’)))
for err in errors:
print(“Line “, str(err[0]), “: ” + err[1])

file_name = sys.argv[1]
string_name = “string”

print “This is the name of the script: “, sys.argv[0]
print “This is the file: “, sys.argv[1]
if len(sys.argv) > 2:
print “This is the string to find: “, sys.argv[2]
string_name = str(sys.argv[2])
print “This is the name of the string: “, string_name

#Main:
is_there = find(file_name, string_name)
print(is_there)
if is_there is True:
find_line(file_name, string_name)

curl

All

Intro

Curl is an excelent to test http responses.  Interesting that since it’s open source you can see where the could might fail, for example:

Code

if(!stream->bodystarted) {

   failf(data, “HTTP/2 stream %d was closed cleanly, but before getting “” all response header fields, treated as error”,stream->stream_id);*err = CURLE_HTTP2_STREAM;return -1;

}

Therefore in case you see HTTP/2 stream %d was closed cleanly, but before getting you would know that the header is coming broke or the body of the request is absent.