Deleting rows starting with a character and word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting rows starting with a character and word
# 1  
Old 01-10-2013
Deleting rows starting with a character and word

Hi,

I have multiple files of same format and I want to delete the lines starting with # and The from all of them

I am using
Code:
 egrep -v '^(#|$)'

for # but unable to do for both # and The

Please guide
Thanks
# 2  
Old 01-10-2013
try:
Code:
egrep -v '^[#$]' infile

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 01-10-2013
Code:
egrep -v '^(#|The)' infile

?
This User Gave Thanks to RudiC For This Post:
# 4  
Old 01-10-2013
I have used both the following and they are working, but I want to delete both # and The in one command.

Code:
 egrep -v '^(#|$)'  
 egrep -v '^(The|$)'

# 5  
Old 01-10-2013
Code:
grep '^[^$|^#]' file

This User Gave Thanks to Yoda For This Post:
# 6  
Old 01-10-2013
try also:
Code:
egrep -v '^(#|The|[$])' infile

# 7  
Old 01-10-2013
@bipinajith: Thanks. Its working but deleting lines starting with TER that I dont want.
@rdrtx1: Thanks its working fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get first word only starting of a line

Hi, I am trying to get longest line in a .gz file without extract the file. I am using the below command to get the longest line. zcat /a/b/c/file.gz |awk '{print length, $0}'|sort -nr|head -1 247 AAAAAAAAAAAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBBBBBAAAAAA CCCCCCCCCCC DDDDDDDDDDDD EEEEEEEEEEEEEE... (4 Replies)
Discussion started by: k_manimuthu
4 Replies

2. UNIX for Dummies Questions & Answers

Count of rows starting with 01 in a file

Hi I am very new to unix and please help me in solving the below problem I have a file with 50000+ rows. Each row(line) start with 01 or 02 or 03. Now i have to get the count of rows starting with 01 only, Thanks in advance (3 Replies)
Discussion started by: nmakkena
3 Replies

3. Shell Programming and Scripting

Replace a word in a string starting with another word

Hi All, I have a file in which a number of lines are starting with similar first word but different next words. I want to replace the any nth word(not 1st or 2nd) with another word. Eg:- My file contains are like this:- Ram is a boy. Ram is a good boy. Ram plays cricket. Here I want to... (2 Replies)
Discussion started by: mukeshbaranwal
2 Replies

4. 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

5. Shell Programming and Scripting

Deleting lines not starting with numbers with sed

Title says all :p Thanks for your help (4 Replies)
Discussion started by: drbiloukos
4 Replies

6. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

7. Shell Programming and Scripting

Deleting specific rows in large files having rows greater than 100000

Hi Guys, I need help in modifying a large text file containing more than 1-2 lakh rows of data using unix commands. I am quite new to the unix language the text file contains data in a pipe delimited format sdfsdfs sdfsdfsd START_ROW sdfsd|sdfsdfsd|sdfsdfasdf|sdfsadf|sdfasdf... (9 Replies)
Discussion started by: manish2009
9 Replies

8. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

9. Shell Programming and Scripting

Command to parse a word character by character

Hi All, Can anyone help me please, I have a word like below. 6,76 I want to read this word and check if it has "," (comma) and if yes then i want to replace it with "." (dot). That means i want to be changed to 6.76 If the word doesnot contain "," then its should not be changed. Eg. ... (6 Replies)
Discussion started by: girish.raos
6 Replies

10. UNIX for Dummies Questions & Answers

Deleting lines starting with spaces then non-numerals

I did a search but couldn't find a thread that seemed to answer this but my apologies if it has been answered before. I have some text files and I need to remove any line that does not start with a number (0-9). In actuality every line like this starts with a 'T' (or 't') but there are a... (5 Replies)
Discussion started by: skray
5 Replies
Login or Register to Ask a Question