Delete from another file that matched on log file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Delete from another file that matched on log file
# 1  
Old 10-23-2018
Delete from another file that matched on log file

I want to write a script using Oscam Cardsharing server
this is my test:
Code:
cat oscam.log | grep "error"

sample output:
Code:
2018/10/17 16:43:07 5C94A12E p    (cccam) cccam(r) test.dyndns.org: login failed, error

Once I've found an error, I need to remove its information inside another file :
oscam.server
Code:
[reader] label                         = test.dyndns.org 
protocol                      = cccam 
device                        = test.dyndns.org,12000 
key                           = 0102030405060708091011121314 
user                          = 12345 
password                      = 12345 
inactivitytimeout             = 30 
group                         = 1 
cccversion                    = 2.1.2 
cccmaxhops                    = 0 
cccmindown                    = 1 
ccckeepalive                  = 1  

blalbal 
blalblalb 
blalblalb 
lablalb

I need to delete those "test.dyndns.org" lines that matched. I would like to keep only the following :
Code:
blalbal 
blalblalb 
blalblalb 
lablalb

So far, I've tried the following code :
Code:
awk '/test.dyndns.org/{while(getline && $1 != ""){}}1' oscam.server

#output is :
Code:
[reader]  

blalbal 
blalblalb 
blalblalb 
lablalb

But the line [reader] is still present. What could I do to remove the block entirely?


i dont know how variable in perl because will be random url that contains words or only numbers i didnt prefer this method i gave an example


Code:
perl -sp0e 's/\[reader\]((?!\n\n).)*\Q$input\E((?!\n\n).)*((\n\n)|(\n?\Z))//sig' -- -input="<DESIRED INPUT HERE>" oscam.server


Moderator's Comments:
Mod Comment Please use CODE tags (for data as well) as required by forum rules!

Last edited by rbatte1; 10-23-2018 at 11:02 AM.. Reason: Changed ICODE tags to CODE tags
# 2  
Old 10-23-2018
Welcome to the forum.


The structure of your "oscam.server" is not quite clear; it wasn't before I inserted the required CODE tags for data. It's all in one line; please edit your post and correct the sample data.


Is the [reader] line immediately adjacent to the pattern line? Or do we just have to match itself?
# 3  
Old 10-23-2018
Check again, now formatted, im sorry im totally new in this forum
# 4  
Old 10-23-2018
No problem. Your code snippet applied to the file as is now yields

Code:
awk '/test.dyndns.org/{while(getline && $1 != ""){}}1' file

blalbal 
blalblalb 
blalblalb 
lablalb

which is close to what you want, no [reader] line.
Does that file end after the "blabla...", or do we need a termination criterion?
# 5  
Old 10-23-2018
Yep, till delete the first blank line, but also delete
Code:
[reader]

, that matching from the log, but how to input beetween 2 words this search? I didn't found yet
# 6  
Old 10-23-2018
Please rephrase.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Not able to delete log file

On my solaris-10 box, there are two log files which are being used (written by) some application. Those are hige files of 3 gb and 5 gb. I tried to nullify it, but it shows me zero size and after few seconds it will show me its original size. "ls -ltr" shows me big size, but "du -sh file" shows me... (7 Replies)
Discussion started by: solaris_1977
7 Replies

2. Shell Programming and Scripting

ksh : need to get the 4 th line above and 2 nd below the matched pattern in the log file

I have a log file as given below 012/01/21 10:29:02 (111111) Processing Job '23_369468343464564' 2012/01/21 10:29:02 (111111) Making Job '23_369468343464564.0'... 2012/01/21 10:29:04 (111111) Jobnumber '23_369468343464564' was successful 2012/01/21 10:29:04 ... (12 Replies)
Discussion started by: rpm120
12 Replies

3. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

4. Shell Programming and Scripting

Count of matched pattern occurences by minute and date in a log file

Anyone knows how to use AWK to achieve the following Sun Feb 12 00:41:01-00:41:59 Success:2 Fail:2 Sun Feb 12 00:42:01-00:42:59 Success:1 Fail:2 Sun Feb 12 01:20:01-01:20:59 Success:1 Fail:2 Mon Feb 13 22:41:01-22:41:59 Success:1 Fail:1 log file: Success Success Fail Fail ... (9 Replies)
Discussion started by: timmywong
9 Replies

5. Shell Programming and Scripting

Log file - Delete lines

Hello, I tried to search on the site a way to delete lines on log files but I didn't find what I am looking for... I hope someone will be able to help me. I do not know how to explain this, so I will do my best. I have a log file and I want to delete all second lines. Example : ... (3 Replies)
Discussion started by: Aswex
3 Replies

6. Shell Programming and Scripting

Match a line in File 1 with Column in File 2 and print whole line in file 2 when matched

Hi Experts, I am very new to scripting and have a prb since few days and it is urgent to solve so much appreciated if u help me. i have 2 files file1.txt 9647810043118 9647810043126 9647810043155 9647810043161 9647810043166 9647810043185 9647810043200 9647810043203 9647810043250... (22 Replies)
Discussion started by: mustafa.abdulsa
22 Replies

7. Shell Programming and Scripting

Count of matched pattern occurences by time in a log file

We have a log file, the format is similar to this: 08/04/2011 05:03:08 Connection Success 08/04/2011 05:13:18 Connection Success 08/04/2011 05:23:28 Connection Fail 08/04/2011 05:33:38 Connection Success 08/04/2011 06:14:18 Connection Success 08/04/2011 06:24:28 Connection Fail 08/04/2011... (6 Replies)
Discussion started by: clu
6 Replies

8. Shell Programming and Scripting

Delete log file entries based on the Date/Timestamp within log file

If a log file is in the following format 28-Jul-10 ::: Log message 28-Jul-10 ::: Log message 29-Jul-10 ::: Log message 30-Jul-10 ::: Log message 31-Jul-10 ::: Log message 31-Jul-10 ::: Log message 1-Aug-10 ::: Log message 1-Aug-10 ::: Log message 2-Aug-10 ::: Log message 2-Aug-10 :::... (3 Replies)
Discussion started by: vikram3.r
3 Replies

9. Shell Programming and Scripting

save every line in log file with matched string

i have been doing this script to match every line in a current log file (access_log) with strings that i list from a path (consist of 100 of user's name ex: meggae ).. and then make a directory of every string from the text file (/path/meggae/) --->if it matched.. then print every line from the... (3 Replies)
Discussion started by: meggae
3 Replies

10. UNIX for Dummies Questions & Answers

mass delete a certain string in a .log file

Hey all. I have a file that has roughly 115,000 lines in it. There are a few lines of information that I don't want in it, but I don't want to search through all of the lines to find the ones that I don't want. Is there a way to do a mass delete of the lines that I don't want? Thanks for the... (4 Replies)
Discussion started by: jalge2
4 Replies
Login or Register to Ask a Question