Script Linux Bash, print grep output based on number of words in line

I’m trying to write a scirpt for the bash shell. I’m given 4 parameters:

  1. path of a directory
  2. extension of a file
  3. a word
  4. a number

I have to look for all files and files of subdirectories of the path, for files with the given extension. Then, look in the files for the lines matching the word given, but only if the number of words in the line is bigger or equal to the number provided.
For example:
If localDirectory has: image.png script.sh text.txt.
And text.txt has:

This is a text file
It contains many words
This is an example for a simple text file

Then give the command: ./example.sh localDirectory txt text 7
I should output: This is an example for a simple text file.

For now, my script looks like this:

if [ "$#" -ne 4 ];
then
  echo "Not enough parameters"
  exit 1
fi
find $1 -name "*.$2" -exec grep -wi $3  {} ;

And it works just fine for the first 3 goals, I just don’t know how to filter now the result such that the line has a greater or equal number of words as $4.

I could of course create a new file and output there, and then read from it and print only the relevant lines, but I would rather do this without creating new files.

I’m very new to shell scripting.

Any ideas?

windows 10 – Can I re-print a past print without having the source document?

On Windows 10, I printed a document last night and, through pure carelessness, didn’t save it (I was in a hurry and thought it’d be a one-off) and don’t have the print to make a copy (it was a cut-out router template for some woodworking stuff, it’s sawdust now), and now I want another copy of it.

I checked my printer (Brother MFC-9340CDW) but afaict it doesn’t remember past documents for reprints. I also checked the software I made the document in (it does have auto-save capabilities) but, long story short, no luck there.

My question is: Does Windows cache these somewhere or maintain a history? Can I print another copy without having the source document available any more?

If it matters, it was the last thing I printed.

deletion – Print sensitive info without leaving data on the printer

I’m not sure if there is already a question here about this because I can’t find anything. But I’m wondering if there are any “safer” ways to print sensitive information without leaving traces on the printer (sensitive data in caches, internal memory, etc.), or at least ways to reduce those traces.

Suppose I need to print some codes, passwords, secret data, or anything sensitive anyway. After you have printed the data, you can put the sheet in a safe place (like a safe), but the printer is going to remain in its usual place where it could be accessed by a malicious actor (I don’t think many people lock their printers in a safe).

This might be equivalent to asking how to delete any data left in the memory of a printer, or at least reduce the probability of leaving any sensitive data in it. Maybe printing some more megabytes of documents after the sensitive data will help “overwriting” the memory on the printer? I have no idea.

python – RegEx to find a keyword & print whole line with matches

I need to create a regexp to be used in python where a keyword is to be matched in a output & whole line with exact matches should be displayed , kindly assist

Some_output = "hello how are you something. nhello how are you2 something.nhello how are you3 
something."
Search_String ="you2
Expected Output - how are you2 something.
vv = re.findall(r'.*you2.*',Some_output)
print(vv)  - returns nothing 

php – Retrieve some post which match a specific taxonomy and print their url and some relative taxonomy/field in a file?

as specified in the title I should create a (php?) file to upload to the server that retrieves the url of the posts that correspond to a certain taxonomy and simply print the url of these (and some other datas) .

Can you give me a tip or suggestion?

Thank you all

Print in page in html

I am create a print button. It is printable but the error is "Table head is repeat at the page end at the time of print" which is shown in below image.
enter image description here

how to remove or set the repeated "table heading".

Here is my code-
enter image description here

python – This is a Seat Reservation System. How can this program be able to print tickets of more than 1 customer and the ticket should be “Name, Seat No.”?

available_seats = (‘1A’, ‘1B’, ‘2A’, ‘2B’, ‘3A’, ‘3B’, ‘4A’, ‘4B’, ‘5A’, ‘5B’, ‘6A’, ‘6B’, ‘7A’, ‘7B’, ‘8A’, ‘8B’, ‘9A’, ‘9B’, ’10A’, ’10B’ )
user_tickets = {}

def print_tickets():
“””Print the tickets of the user.”””
for user_name, seats in user_tickets.items():
print(f”nCustomer, {user_name.title()}, has chosen {len(seats)} seat(s).”)
for seat in seats:
print(f”tSeat number: {seat}”)

print(“Welcome To The Seat Booking Portal!”)

start = input(“Would you like to book a seat?”)
if start.lower() == ‘yes’:
while True:
seats = ()
wanted_seats = input(“How many seats do you need?”)
wanted_seats = int(wanted_seats)
if wanted_seats > len(available_seats):
print(f”n–I’m sorry, we only have {len(available_seats)} ”
“seats available–“)
print(“–Please try again–“)
continue

    user_name = input("Enter your name:")

    while True:

        print("nHere are the available seats:")
        for seat in available_seats:
            print(seat)

        seat = input("Please enter the number of the seat you would like to book:")

        if seat in available_seats:
            available_seats.remove(seat)
        else:
            print("n--I'm sorry you have chosen an invalid seat--"
                "n-Please try again-")
            continue

        seats.append(seat)

        if wanted_seats > 1:
            print("nYou can now choose another seat.")
            wanted_seats-=1
            continue
        else:
            break

    user_tickets(user_name) = seats

    if available_seats:
        go_again = input("Would you like to let someone else book their tickets? (yes/no)")
        if go_again == 'no':
            break
    else:
        break
print_tickets()
print("nWe will now redirect you to the payment portal."
    "nThank You for choosing us.")

else:
print(“You can always come by later!”)

python – I wrote this code, and I’m struggling to remove readlines, open, and the print statement in my code

I wrote this code, and I’m struggling to remove readlines, open, and the print statement in my code since it says in the homework that we are not allowed to use these statements in the functions file code.

Any help is highly appreciated, I struggling to fix it coz

functions.py file:

def median(file_handle):
    """
    -------------------------------------------------------
    Extracts numbers from a file and calculates their median value.
    Use: median = locate_median(file_handle)
    -------------------------------------------------------
    Parameters:
        file_handle - a file already open for reading (file handle)
    Returns:
        m - median of the values in file_handle (float)
    -------------------------------------------------------
    """
    infile = open(file_handle, "r")
    numbers = ()
    for line in infile.readlines():
        line = line.rstrip()
        words = line.split(",")
        for word in words:
            numbers.append(int(word))

    numbers.sort()
    print(numbers)
    mid = len(numbers) // 2
    if len(numbers) % 2 == 0:
        m = (numbers(mid - 1) + numbers(mid)) / 2
    else:
        m = numbers(mid)
    return m

t02.py file:

from functions import median


file_name = input("Enter file name: ")

median = median(file_name)
print("Median is:", median)

outfile = open("out_t02.txt", "w")
outfile.write("Median is: ")
outfile.write(str(median))

print("Data written into out_t02.txt")
outfile.close()

The numbers.txt file that we have to work with:

10,20,30
40,50,60
90,80,70
11,22,13 
14,14,20

The code’s goal is:

Write a function median that takes a file handle as an parameter and find the median of a
group of scores.

Requirements:

  • Read the group of scores from a file (that contains numbers only, each line has 3
    numbers), and put the scores into a list of numbers.
  • Your function must sort the elements in order. You can use the build-in sort method
  • Find and return the median from the sorted list of scores. Here a median is the middle
  • element of a sorted list if the number of elements is odd, and the average of the two
    middle elements if the number of elements is even.
  • for a list (40,20,50,10,30), the median is 30 as it is the middle element (odd number of
    elements in the sorted list)
  • for a list (40,60,30,10,50,20), the median is 35 as it the average of 30 and 40 (two
    middle items in an even number of elements in the sorted list)

Save the function in a PyDev library module named functions.py .

A sample run for the function:

median(file_handle) returns 35.

Write a testing program named t02.py that tests the median function and write/print the
results to the output file out_t02.txt

• Your function should ask the user for the input file name they would like to open.

• Test your program with the sample file provided numbers.txt.

buses – Greyhound bus ticket (print at home)

If it’s a suitcase, they may ask to check in (which goes in the check in bin in the belly of the bus). If it’s a back pack or something similar, you can carry it with you. As far as the ticket goes, you can print it from your home, print it out from a kiosk at the bus stand or use your smartphone to scan the e ticket and avoid any printing altogether.