Non-root script used search and list specific key words
Hy there all. Im new here. Olso new to terminal & bash, but it seams that for me it's much easyer to undarsatnd scripts than an actual programming language as c or anyother languare for that matter.
S-o here is one og my home works s-o to speak.
Write a shell script which:
-only works as a non-root user
-gets a directory or tar archive (*.tar.gz, *.tgz) as the main parameter
-traverses all of it and its subdirectories/archives to find all files containing “much Open, such Stack” in them and print their file names (-n parameter must be given for this)
-if tar archives are found, search for files in them as well without leaving any evidence that you unarchived anything
-print the number of found files (-c parameter must be given)
-check all arguments, both -c and -n may or may not have been given
NOTES:
-check all your parameters at the beginning of the script, and save the “presence” of -n and -c in some variables for later use.
The parameters may come in ANY order so do be aware of that.
you can use `$0 param1 param2 …` to make your script “recursive”.
my curent script looks like this:
olso i had one more script done wich did made more sens to me at the time, still dose:
as you can se the codes uses one of the to functions "ls" or "find" ( one being disabled )
My question is this:
why dont i get any kind of output on the second code no mater what path i give it, beeing tar, directory or a txt file, and gain no matter what function i use be it find or ls.
and why dose the first code works? sort of...
Any ideas?
Last edited by Crisso2Face; 06-16-2016 at 09:25 AM..
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.
Please review the rules, which you agreed to when you registered, if you have not already done so.
More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.
Hi All,
I have a file abc.txt
Database unique name: NEPAL
Database name: NEPAL
Services: NEPAL_COB,NEPAL_PROD
output i need is it should search "Services" and it that search "COB" word
so output i need is like
NEPAL_COB (3 Replies)
Being new to the forum, I tried finding a solution to find files containing 2 words not necessarily on the same line.
This thread
"List all file names that contain two specific words."
answered it in part, but I was looking for a more concise solution.
Here's a one-line suggestion... (8 Replies)
Hi,
Need your help for this scripting issue I have. I am not really good at this, so seeking your help.
I have a file looking similar to this:
Hello, i am human and name=ABCD.
How are you?
Hello, i am human and name=PQRS.
I am good.
Hello, i am human and name=ABCD.
Good bye.
Hello, i... (12 Replies)
Hello,
I'm trying to write a bash script that will search for words from one list that may be found in another list. Once the record is found, it will create a new text file for each word.
For example, list1.txt contains the following:
Dog
Cat
Fish
List2.txt contains
Dog - Buddy 14... (3 Replies)
I have the need to search a text file from my unix script to determine if it contains the strings of: 'ERROR' and/or 'WARNING'.
By using Grep I can search the file and return a where one of these strings exists. Like this:
cat myfile.txt | grep ERROR
Output:
PROCESS ERROR HERE ... (3 Replies)
Hi, all:
I would like to search all files under "./" and its subfolders recursively to find out
those files contain both word "A" and word "B", and list the filenames finally.
How to realize that?
Cheers
JIA (18 Replies)
Hi,
I have a file content like:
:
:
<span class="ColorRed"> 1.23</span><br>
:
:
the value 1.23 will be changed from time to time, and I want to use a shell script command, e.g grep or sed, to retrieve only the value, how to do it?
Thanks!
Victor (6 Replies)
Hello:
I need help adding a key word search to my bash script. I have the following script. My boss whats the user to be able to add a search word e.g. unknown failures for the script to search the logs through and find the instances. I had originally done it so it grepped for unknown... (8 Replies)
I have a file that contains the following:
Mon Dec 3 15:52:57 PST 2o007: FAILED TO PROCESSED FILE 200712030790881200.TXT - exit code=107
Tue Dec 4 09:08:57 PST 2007: FAILED TO PROCESSED FILE 200712030790879200a.TXT - exit code=107
This file also has a lot more stuff since it is a log file.... (2 Replies)
Hello,
I want an one line command that brings me back all the files in a folder that contain 4 specific words anywhere inside them.
I want to use find,xargs and grep. for example i know for one word the command would be:
find . | xargs grep 'Word1'
But i don't know for 4 specific words... (13 Replies)