Grepping exact pattern and deleting the rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping exact pattern and deleting the rows
# 8  
Old 05-02-2016
Quote:
Originally Posted by am24
.
.
. the solution for teh second question i asked will be
grep -v '^..513... ' sample > op6
Yes

Quote:
Thanks. I have tried the code. But getting an error message as below.
.
.
.
Quote:
Originally Posted by Don Cragun
If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk.
This User Gave Thanks to RudiC For This Post:
# 9  
Old 05-02-2016
Hello am24,

Seems to be you are using Sun/Solaris box, usually nawk should work on it not sure why you are getting an error. Please on a Solaris/SunOS system, change awkto /usr/xpg4/bin/awk , /usr/xpg6/bin/awk. Kindly do let me know how it goes then.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 10  
Old 05-02-2016
Yes, as regular expression ^ means the start and $ the end of the line.
If it really matters for position better go with Rudi's example as it is more straight and easy.
This User Gave Thanks to zaxxon For This Post:
# 11  
Old 05-02-2016
Thanks everyone.

Yes i am working on Solaris.I have tried using nawk, /usr/xpg6/bin/awk and /usr/xpg6/bin/awk. But same error again.

Code:
/usr/xpg6/bin/awk '(substr($1,3,3) != 51[35])'  sample > op9
/usr/xpg6/bin/awk: Command not found

Code:
/usr/xpg4/bin/awk '(substr($1,3,3) != 51[35])' sample > op10
/usr/xpg4/bin/awk: syntax error  Context is:
>>>     (substr($1,3,3) != 51[  <<<

I have tried below by keeping only '513' . Now the below both worked.

/usr/xpg4/bin/awk '(substr($1,3,3) != 513)' sample > op11

nawk '(substr($1,3,3) != 513)' sample > op12


May be some wrong in mentioning two patterns in the code. I am not sure.

Regards,
am24
# 12  
Old 05-02-2016
Hello am24,

Could you please use following and let me know if this helps.
Code:
/usr/xpg4/bin/awk '(substr($1,3,3) != 513 && substr($1,3,3) != 515)' sample > op10

Thanks,
R. Singh
# 13  
Old 05-02-2016
You need to double quote the bracket expression "51[35]" - it is a regex, not a number, and a string comparison, not an integer comparison.
# 14  
Old 05-02-2016
Hi Ravinder,

The below code worked.
/usr/xpg4/bin/awk '(substr($1,3,3) != 513 && substr($1,3,3) != 515)' sample > op10

Hi Rudi,

The below did not work. The output 'op16' same as the input 'sample'

nawk '(substr($1,3,3) != "51[35]")' sample > op16

Still trying on it.

Regards,
am24
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To search exact pattern

Hi, I need to search the exact pattern in a file file.txt AUS.txt|AUS.chk NZ.txt|NZ.ch I am getting the result as AUS.txt|AUS.chk with below code but i need only AUS.txt to be printed grep AUS.txt file.txt CODE tags also for data files (8 Replies)
Discussion started by: rohit_shinez
8 Replies

2. Shell Programming and Scripting

Printing next two lines from a file after grepping a specific pattern

Hi I have a file like # vi require.txt 1,BANK,Read blocks that cycle. yellow Read blocks. 2,ACCOUNT,Finished Red Finished . 3,LOAN, pipe white pipe 4,PROFIT,Resolve. black Resolve Am using like cat require.txt | grep -w ACCOUNTThe output I get is (8 Replies)
Discussion started by: Priya Amaresh
8 Replies

3. Shell Programming and Scripting

To find the exact pattern

My Input : Hi editor this is the exact pattern which we looking for the previous patternmatch My code: awk '/pattern/ { print a } { a = $0 }' Current output : exact previous (3 Replies)
Discussion started by: Roozo
3 Replies

4. UNIX for Dummies Questions & Answers

Deleting a pattern in UNIX without deleting the entire line

Hi I have a file: r58778.3|SOURCES={KEY=f665931a...,fw,221-705}|ERRORS={16_1:T,30_1:T,56_1:C,57_1:T,59_1:A,101_1:A,115:-,158_1:C,186_1:A,204:-,271_1:T,305:-,350_1:C,368_1:G,442_1:C,472_1:G,477_1:A}|SOURCE_1="Contig_1092402550638"(f665931a359e36cea0976db191ff60ff09cc816e) I want to retain... (15 Replies)
Discussion started by: Alyaa
15 Replies

5. UNIX for Advanced & Expert Users

merge two tab delimited file with exact same number of rows in unix/linux

Hi I have two tab delimited file with different number of columns but same number of rows. I need to combine these two files in such a way that row 1 in file 2 comes adjacent to row 1 in file 1. For example: The content of file1: field1 field2 field3 a1 a2 a3 b1 b2 b3... (2 Replies)
Discussion started by: mary271
2 Replies

6. Shell Programming and Scripting

how to finding the exact pattern

I have a output like below: A1 B2 C1 D3 A12 B4 A14 I am trying to find A1 by using grep grep -i "A1" But I got (4 Replies)
Discussion started by: anupdas
4 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

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

9. Shell Programming and Scripting

Grepping for Exact Strings

ok, apparently this is a very difficult question to answer based on my searches on google that came up fruitless. what i want to do is grep through a file for words that match a specified string. but the thing is, i keep getting all words in the file that have the string in them. say for... (27 Replies)
Discussion started by: SkySmart
27 Replies

10. Shell Programming and Scripting

Grepping 1 line above and below pattern

I have a pattern:: xldn3176bap>arj SOCRATES_MAIN_LNX | grep " FA " 10/04/2007 21:01 10/04/2007 21:01 FA 1776752/1 1 I want the line above this line and the line below it too. Can anyone tell me how it can be done? - iAm4Free (4 Replies)
Discussion started by: iAm4Free
4 Replies
Login or Register to Ask a Question