Delete lines starting with these strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete lines starting with these strings
# 1  
Old 07-25-2013
Delete lines starting with these strings

Platform : RHEL 5.8


I have text file called myapplication.log . In this file, I have around 800 lines which start with the followng three strings

Code:
PWRBRKER-3493
PWRBRKER-7834
SCHEDULER-ERROR

How can I delete these lines in one go ?
# 2  
Old 07-25-2013
Have you read the manual pages for egrep?

Have a look at the -v option and consider the special character ^ meaning the start of the record.


Does this help you out?



Robin
Liverpool/Blackburn
UK
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 07-25-2013
Thank you Robin. My requirement is to delete those lines. So grep or egrep won't help.
# 4  
Old 07-25-2013
Quote:
Originally Posted by omega3
Thank you Robin. My requirement is to delete those lines. So grep or egrep won't help.
This is what Robin meant:
Code:
egrep -v "^PWRBRKER-3493|^PWRBRKER-7834|^SCHEDULER-ERROR" myapplication.log > tmp; mv tmp myapplication.log

This User Gave Thanks to Yoda For This Post:
# 5  
Old 07-25-2013
Thank you very much Yoda.
# 6  
Old 07-26-2013
Code:
awk '!/^PWRBRKER-3493|^PWRBRKER-7834|^SCHEDULER-ERROR/' myapplication.log

# 7  
Old 07-26-2013
if you want to delete first 3 lines compulsorily, without matching the patterns then you can use
Code:
sed '1,3d' myapplication.log > myapp;mv myapp myapplication.log

deletes the 1st 3 lines from the file.
This User Gave Thanks to Little For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all lines except a line starting with string

Shell : bash OS : RHEL 6.8 I have a file like below. $ cat pattern.txt hello txt1 txt2 txt3 some other text txt4 I want to remove all lines in this file except the ones starting with txt . How can I do this ? (4 Replies)
Discussion started by: omega3
4 Replies

2. Shell Programming and Scripting

Delete all lines starting with # character

Tool used : VIM editor that comes with RHEL 7.4 I have a file like below. It has around 300 lines like below. All the lines starting with # are comments. For readability, I removed all lines starting with # from vi (vim editor) using the command :g/^#/d . It seemed to have worked. But, which... (8 Replies)
Discussion started by: John K
8 Replies

3. Shell Programming and Scripting

How to delete lines starting with specific string?

Dear all, I would like to delete even lines starting with "N" together with their respective titles which are actually odd lines. Below is the example of input file. I would like to remove line 8 and 12 together with its title line, i.e., line 7 and 11, respectively.... (2 Replies)
Discussion started by: huiyee1
2 Replies

4. Shell Programming and Scripting

Delete multiple lines starting with a specific pattern

Hi, just tried some script, awk, sed for the last 2 hours and now need help. Let's say I have a huge file of 800,000 lines like this : It's a tedious job to look through it, I'd like to remove those useless lines in it as there's a few thousands : Or to be even more precise : if line1 =... (6 Replies)
Discussion started by: Zurd
6 Replies

5. Shell Programming and Scripting

delete lines starting with a pattern

i have a file sample.txt containing i want to delete lines starting with 123 neglecting spaces and tabs. but not lines containing 123. i.e. i want files sample.txt as help me thanxx (4 Replies)
Discussion started by: yashwantkumar
4 Replies

6. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

7. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

8. UNIX for Dummies Questions & Answers

Delete lines with duplicate strings based on date

Hey all, a relative bash/script newbie trying solve a problem. I've got a text file with lots of lines that I've been able to clean up and format with awk/sed/cut, but now I'd like to remove the lines with duplicate usernames based on time stamp. Here's what the data looks like 2007-11-03... (3 Replies)
Discussion started by: mattv
3 Replies

9. Shell Programming and Scripting

Grep and delete lines except the lines with strings

Hi I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings. Ex: file name 'test' test: approved package waiting for approval package disapproved package removed package approved... (14 Replies)
Discussion started by: vj8436
14 Replies

10. Shell Programming and Scripting

Delete lines starting with XX or YY or ZZ or ....

Hi There! My final task for today is to delete lines starting with certain numbers for e.g., my text block is and i want to delete all lines starting with 11 or 17 or 21 I know i can use multiple sed commands like sed '/^11,/d' <filename> sed '/^17,/d' <filename> sed '/^21,/d'... (2 Replies)
Discussion started by: orno
2 Replies
Login or Register to Ask a Question