LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-17-2014, 03:11 AM   #1
MaryG
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Rep: Reputation: 0
Smile Exclude some records from a grep search using number line


Hi,
I have a text file with 3000 record like this:

Code:
123 dkdkgm
123 dkfkgfkjg
ORA dkfkgk
2345 dkfkgkg
234k dkdfkffk
...
I need to grep "123" but I want to exclude a list of record from this search. I only know the number line of those records I want to exclude. How can I do that?
 
Old 01-17-2014, 03:20 AM   #2
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 273Reputation: 273Reputation: 273
I don't know if I've understood.
If you have a file and in this file want to exclude some lines (you know only the number) and grep 123 for the remaining, a way could be (in the example 1,2 5 are the number of line that you exclude)

Code:
cat your_file | sed '1d; 2d; 5d'| grep 123

Last edited by kooru; 01-17-2014 at 03:21 AM.
 
1 members found this post helpful.
Old 01-17-2014, 03:41 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,834

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
Use a more appropriate tool - awk for example has a variable that is the record numer you can test. Then use regex on only the lines of interest to you.
 
Old 01-17-2014, 03:42 AM   #4
MaryG
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks!
This is my script:

Code:
#!/bin/bash


LISTA_ERRORI=`grep -n "ORA-01466" script.out | cut -f1 -d:`

for ERR_LINE in ${ERROR_LIST}
do
  ADD_RECORD=$ADD_RECORD" $[$ERR_LINE-1]d; $[$ERR_LINE-2]d;"
done

#echo $ADD_RECORD

cat script.out  | sed '$[ADD_RECORD]'| grep -v "ORA-" |  grep -v "ORA-01466" | wc -l
ADD_RECOD variable is like this:
Code:
5857d; 5856d; 6826d; 6825d; 6834d; 6833d; 10984d; 10983d; 12206d; 12205d; 12210d; 12209d; 12213d; 12212d; 12424d; 12423d; 13038d; 13037d; 13096d; 13095d; 18088d; 18087d; 18119d; 18118d; 18126d; 18125d; 18305d; 18304d; 18533d; 18532d; 19315d; 19314d; 19373d; 19372d; 20727d; 20726d;
When I execute my script I get this error:
sed: -e expression #1, char 2: unknown command: `['
0
 
Old 01-17-2014, 03:50 AM   #5
kooru
Senior Member
 
Registered: Sep 2012
Posts: 1,385

Rep: Reputation: 273Reputation: 273Reputation: 273
If you use ADD_RECORD as a normal variable "23d; 234d; 34563d; 22d;" then you can use:

Code:
sed "${ADD_RECORD}"
If you use ADD_RECORD as a array with one only long element as "23d; 234d; 34563d; 22d;" then you can use

Code:
sed "${ADD_RECORD[@]}"
You must adapt the script for this.

Last edited by kooru; 01-17-2014 at 04:34 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] grep won't return a number at end of line jgrizich Linux - Newbie 7 10-15-2012 01:20 PM
[SOLVED] grep with pattern and line number mohitvad Linux - Newbie 1 09-14-2012 05:00 PM
Sed/awk/grep search for number string of variable length in text file Alexr Linux - Newbie 10 01-19-2010 02:34 PM
GREP: how to specify a line or lines where to search carolflb Linux - Newbie 7 11-23-2009 09:45 AM
start grep at line number secretlydead Linux - General 2 09-20-2007 07:03 AM


All times are GMT -5. The time now is 06:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration