0% found this document useful (0 votes)
11 views6 pages

Python Scripting Assignments Overview

The document outlines a series of programming assignments focused on file handling and text processing in scripts. Assignments include checking for file existence, reading user input for odd/even numbers, counting lines in a file, creating directories and files with specific content, extracting error messages from logs, and replacing text in files. Each assignment requires the implementation of specific coding tasks with expected outputs.

Uploaded by

rajveer12141618
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Python Scripting Assignments Overview

The document outlines a series of programming assignments focused on file handling and text processing in scripts. Assignments include checking for file existence, reading user input for odd/even numbers, counting lines in a file, creating directories and files with specific content, extracting error messages from logs, and replacing text in files. Each assignment requires the implementation of specific coding tasks with expected outputs.

Uploaded by

rajveer12141618
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment 1: Ensure the script checks if a specific file exists in the current directory.

If it exists, print
"File exists", otherwise print "File not found".

Code:

Output:
Assignment 2: Write a script that reads numbers from the user until they enter '0'. The script should
also print whether each number is odd or even.

Code:

Output:
Assignment 3: Create a function that takes a filename as an argument and prints the number of lines
in the file. Call this function from your script with different filenames.

Code:

Output:
Assignment 4: Write a script that creates a directory named TestDir and inside it, creates ten files
named [Link], [Link], ... [Link]. Each file should contain its filename as its content (e.g.,
[Link] contains "[Link]").

Code:

Output:
Assignment 6: Given a sample log file, write a script using grep to extract all lines containing
"ERROR". Use awk to print the date, time, and error message of each extracted line.

Code:

Output:
Assignment 7: Create a script that takes a text file and replaces all occurrences of "old_text" with
"new_text". Use sed to perform this operation and output the result to a new file.

Code:

Output:

You might also like