05-10-2011
grep sed and a loop
I have a requirement to search a log file that never rotates for certain values. If I find them I pipe them to a another file. To log file is constanyl being appened with new lines and never rotating Easy so far.
The problem is I dont want to pipe out matches already seen before. One thing I tried was to use sed to put a # at the beginning of each line as it is read. Then the grep would ignore lines starting with #
My problem is I can get it to just add # to the unread lines, it adds another to all lines so each time the log is read so the earliest entries have loads of * infront of them.
I was tryin gto get it to ignore liens with # and then to a for loop for any the new lines e.g. for any not starting with # search for the string and add # to the front. This way is would only add # to lines that dont have one.
Here i swhat I was working with but just cant get that loop to work on lines not starting with #
Any help would be a awesome.
grep -v '^#' test.log | grep "Can not load CRL"
This line ignores lines starting with # and greps the rest for "Can not load CRL"
sed 's/^/#/g' test.log > testnew.log
The line adds the # to the front and creates output file testnew.log I want it to only add # to lines without a # already
mv testnew.log test.log
This line renames\overwrites testnew.log and to test.log If anyone knows how i can write directly to the original file instead of having to write a new file and then overwrite the original would be great as well
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi ,
I am trying a script which takes user input userid . I am stuck how to check whether that is a valid user id or not in the audit log files. My code is :
cd $CCP_AUDIT
cat * > /export/home/$USR/l***/files
echo "UserId:\c"
read UserId
#Date Function
echo "DATE : \c"
read xxx
I... (7 Replies)
Discussion started by: gundu
7 Replies
2. UNIX for Dummies Questions & Answers
alist contain:
a
b
c
d
e
blist contain:
a
b
c
the code:
#!/usr/bin/ksh
cat blist | while read line
do
grep -V "$line" alist > data
done (8 Replies)
Discussion started by: bobo
8 Replies
3. Shell Programming and Scripting
I have a huge file and want to separate it into several subsets.
The file looks like:
C1 C2 C3 C4 ... (variable names)
1 ....
2 ....
3 ....
:
22 ....
23 ....
I want to separate the huge file using the column 1, which has numbers from 1 to 23 (but there are different amount of... (8 Replies)
Discussion started by: AMBER
8 Replies
4. Shell Programming and Scripting
I have a key file
$ cat klist
5 N:8855 CASA VERDE ROAD :32827 :ORLAND
5 N:585 MOLLY LANE :30189 :WOODST
5 N:320 NINA ROAD :32304 :TALLAH
and a data file, see example of the line below:
N:RT 15 & N 7TH STREET :17837 :U SAVE
I need to search by key (2nd field) from klist... (6 Replies)
Discussion started by: migurus
6 Replies
5. Shell Programming and Scripting
Hi all,
I have the below script to get input but i cannot get grep to work.
input1.txt
AAAAAAAAG
input2.txt
>gi|184009.1| LEAFY-like |AAAAAAAAGSGGGDHLPY
However, when i use grep -f input1.txt input2.txt
i cannot get any output matches (note that the match is underlined).
Is it... (8 Replies)
Discussion started by: turkishvan
8 Replies
6. Shell Programming and Scripting
So this is what I'm trying to do:
I have a file called registry.txt which has a list of registry entries I want to search for.
I have another file called inctrl.txt on which I want to perform the search on.
Here's the example contents of registry.txt
SOFTWARE\Microsoft\Security... (3 Replies)
Discussion started by: r4v3n
3 Replies
7. Red Hat
Hello everybody,
I have been searching it, but it seems I am unable to find the correct information, that s why I am asking you guys, hoping somebody get an idea.
Here is my problem :
I want a script to loop until a string is identified in a log file.
Here is the script :
#!/bin/sh... (5 Replies)
Discussion started by: guyiom
5 Replies
8. Homework & Coursework Questions
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I need to search through the users home directories for keywords, display them. The code listed below will show... (7 Replies)
Discussion started by: jcllns1
7 Replies
9. UNIX for Beginners Questions & Answers
Hello -
I am running a script that is outputting to a log. Let call it output.log
I would like to monitor that log until the line "Build Successful" is found.
I think I would need to use the grep command.
How would I do that in a loop?
Thanks
Marty (1 Reply)
Discussion started by: MSpeare
1 Replies
10. Shell Programming and Scripting
Hello,
I have built the following script to check if processes supplied by the argument are running or not.
#!/bin/bash
PROCLIST=$1
PROCESS="0"
ERROR_PROCS=""
IFS='+'
read -ra ADDR <<< "$PROCLIST"
for PROC in "${ADDR}"; do
if ; then
PROCESS=1
... (9 Replies)
Discussion started by: nms
9 Replies
LEARN ABOUT SUSE
scanlogs
SCANLOGS(8) InterNetNews Documentation SCANLOGS(8)
NAME
scanlogs - Summarize and rotate INN log files
SYNOPSIS
scanlogs [norotate]
DESCRIPTION
scanlogs summarizes the information recorded in the INN log files which reside in the pathlog directory set in inn.conf (see newslog(5) for
further details about these log files). It is normally invoked by the news.daily(8) script which performs daily server maintenance tasks.
It invokes "ctlinnd flushlogs" to close the news and error log files, rename them to add ".old" to the file names and open fresh news and
error logs; the active file is also flushed to disk, along with the history database.
By default, scanlogs rotates and cleans out the logs. It keeps up to logcycles old compressed log files in pathlog/OLD (the logcycles
parameter can be set in inn.conf). scanlogs also keeps archives of the active file in this directory.
It invokes tally.control if newgroup.log or rmgroup.log exists in pathlog (see the control.log entry of newslog(5) for more information
about that).
scanlogs displays the contents of errlog and news.crit, if non-empty, and runs innreport to summarize the contents of news and news.notice,
and to update the unwanted.log file amongst other things (see more information about that in innreport(8)).
OPTIONS
Only one option is currently accepted:
norotate
Using this option disables the rotating and cleaning aspect of the log processing: the logs files are only scanned for information and
no contents are altered. If scanlogs is invoked more than once a day, the norotate option should be used to prevent premature log
cleaning.
FILES
See newslog(5) for the list of log files processed by scanlogs.
HISTORY
Written by Landon Curt Noll <chongo@toad.com> and Rich $alz <rsalz@uunet.uu.net> for InterNetNews. Converted to POD by Julien Elie.
$Id: scanlogs.pod 8357 2009-02-27 17:56:00Z iulius $
SEE ALSO
inn.conf(5), innreport(8), news.daily(8), newslog(5), shlock(1), tally.control(8).
INN 2.5.2 2009-05-21 SCANLOGS(8)