Script to create a list of values
I wish to create a script that will look in a file for a certain value (in this case an IP address) and then output it to another file on a seperate line. I have seen it is possible to use AWK and then print the value where it is on the line, the trouble is the value can move from line to line. How can I go about resolving this please?
Newbie to programming so any explanations on what the command is doing is greatly appreciated. Sorry if this has been covered but wasnt sure on what to search for! TIA Jasper |
A nice one-liner question.
Shouldn't take long for someone to trump this. Code:
perl -e 'while(<>){if($_ =~ m/YourPatternHere/){print $&,"\n";}}' filename.ext > outputfile.log |
Hi,
A lot of unix/linux tools are line driven (by default, you can change this behaviour), they parse one line at the time and the tools can do something with/to that line. AWK is also line driven. Something line this: awk '/10.0.0.1/ { print $0 }' infile will print all lines (print $0) if 10.0.0.1 is found (/10.0.0.1/) anywhere on a line, all other lines are not printed. If you want to put the output into another file you can redirect the output: awk '/10.0.0.1/ { print $0}' infile > outfile. The > outfile part makes sure that the output is put in a file called output. Here's a good link to the (gnu) awk documentation: The GNU Awk User's Guide Hope this helps. |
Code:
grep your_search_string input_file.txt > output_file.txt |
This has to be a simple as it can get...
Code:
grep -oh 'YourPatternHere' input_file(s) > output_file.txt Code:
grep -ohe 'YourRegularExpressionHere' input_file(s) > output_file.txt |
Many thanks to all who have replied, there seems to be many different ways I can get the output I want....I will need to mess about with a file until I get it right.
Once many thanks to all who have replied...most helpful!!!!! Cheers Jasper |
All times are GMT -5. The time now is 05:41 AM. |