I have the following code as a file which a user can choose with an option to search in that file. The file name is not specified and can have any name and extension. Now a sample of this file is like this:
I know that I have to useawkorsed and get the result printed in a table format? user may choose a combination of switches as well.
This is the code that I have:
Your input file does not seem to have a consistent format around the "nice" field.
You can read and process your file easily with a while read loop:
This is more elegant than using sed, or awk and if you plan to use either within the read loop, this will certainly be the more efficient and faster option...
I should say thanks to you "Scrutinizer" I got some of the code correctly; however, the loop that you were suggesting, wouldn't work with my code. The reason is: I don't know the name of the file which user checks for date. Above that, user can have a different combination of switches! As a result, I am not able to use $# to get the position. I hope it is clear.
---------- Post updated at 09:18 AM ---------- Previous update was at 09:06 AM ----------
Let say I need to check in a text file that I don't know the name within different options in the following code. How do you get the file to search for regular expressions which user has typed in the command line? I am not a professional, I apologize for silly mistakes and bad explanation.
Hi, glad that you found useful. You could use the while-read loop after you find out about the file:
After you are done with getopts, you can do
as I explained in the other thread.
The filename should then be in $1 and $# should be equal to 1, if the user specified one parameter to the script, besides the command line options...
I would suggest you play around a little with the code to verify these things...
*EDIT*
Just saw your latest installment of your script, and suddenly there is a root password, a server IP address and a regular expression on the command line? I am really not sure what direction you are heading..
Last edited by Scrutinizer; 04-01-2012 at 10:54 AM..
This User Gave Thanks to Scrutinizer For This Post:
In the bash below I am searching the filevirus-scan.log for the Infected files: 0 line (in bold) and each line for OK.
If both of these are true then the function execute is automatically called and processing starts. If both these conditions are not meet then the line in the
file is sent to the... (2 Replies)
In the bash when the user inputs an id to search for the bash currently closes, and if a match is found outputs a new file (match.txt). Is it possible to have not close the bash but rather, on the screen "searching for match" and if a match is found "match found in line.." is displayed... (3 Replies)
In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file.
For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
hello i have search in an old .bash_history and i find this instruction :
xhost `xhost | awk -F: 'NR > 1 {printf ("-%s ", $NF)}'`
someone give me some informations about this instruction?:confused:
thx (2 Replies)
Hi,
I have two files: a.doc and b.txt
I wish to search the strings from file b.txt in a.doc and want to highlight them in a.doc with different colours using Perl or bash./awk/sed?
Please guide me. :)
Thanks!!!!! (10 Replies)
Hello,
Some time ago a helpful awk file was provided on the forum which I give below:
NR==FNR{A=$0;next}{for(j in A){split(A,P,"=");for(i=1;i<=NF;i++){if($i==P){$i=P}}}}1
While it works beautifully on English and Latin characters i.e. within the ASCII range of 127, the moment a character beyond... (6 Replies)
Hi I need a bash script that can search through a text file and when it finds 'FSS1206' I need to put a Letter F 100 spaces after the second instance of FSS1206
The format is the same throughout the file I need to repeat this on every time it finds the second 'FSS1206' in the file
I have... (0 Replies)
Hi All,
I am very new to UNIX and I have tried this for a longtime now and unable to crack it....
There is a file that is continuously updating. I need to search for the string and find the date @ which it updated every day.....
eg:
String is "work started"
The log entry is as below:
... (1 Reply)
Hello,
I am trying to make a bash script that can pull data from a file and then change one part of said data.
I want to search by username and pull the full line. That way there is a way to replace just one part of that line then return it back to the file.
My Data is stored like:
... (1 Reply)
Hi all,
I am new to unix. Anyone knows how to search a file in bash terminal, please kindly tell me.
For example, I want to search file named "myfile" in the entire machine...
Thanks a lot:) (2 Replies)