Eliminating space constraint in grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Eliminating space constraint in grep
# 1  
Old 01-09-2012
Eliminating space constraint in grep

here in the below code just a space between 'Info' and '(' is showing that the patter doesnt match...
Code:
 echo "CREATE TABLE Info  (" | grep -i "CREATE TABLE Info  (" | wc | awk -F' ' '{print $1}'
1
echo "CREATE TABLE Info (" | grep -i "CREATE TABLE Info  (" | wc | awk -F' ' '{print $1}'
0

is there any way we could make it not to consider space as a difference...
# 2  
Old 01-09-2012
Code:
echo "CREATE TABLE Info  (" | grep -i "CREATE TABLE Info[ ]*(" | wc -l

# 3  
Old 01-09-2012
can i use this one too...?
Code:
echo "CREATE TABLE Info  (" | grep -i "[ ]*CREATE[ ]*TABLE[ ]*Info[ ]*(" | wc -l

what if the situation is like this
Code:
cat file1
.
.
.create table blah blah
.
.
create table info (
.
.
etc(many tables)

and
Code:
variable="CREATE TABLE Info   ("
how to make it match for this scenario...
cat file1 | grep -i $variable |wc -l  - - -- this wont work right

# 4  
Old 01-09-2012
echo "CREATE TABLE Info (" | grep -i "[ ]*CREATE[ ]*TABLE[ ]*Info[ ]*(" | wc -l --> It looks right syntactically. But since you're echo-ing just one line, there's not point in piping it to wc -l as you already know the line count is '1'.

Wrap $variable in double-quotes.
Code:
cat file1 | grep -i "$variable" |wc -l

# 5  
Old 01-09-2012
(oh sorry i forgot to put quotes to the variable)but i meant the code wont work because of space parameter between 'info' and '(' in the variable... how to rectify that...? is there any way so that it will check whether that line is present or not in the file even thought there is variable spaces between the words in the variable?

Last edited by vivek d r; 01-09-2012 at 08:26 AM..
# 6  
Old 01-09-2012
Code:
$ cat input
CREATE   TABLE       Info         (
CREATE  TABLE  Info    (
CREATE    TABLE   Info    (
hellow world
hello earth

Code:
$ var="CREATE[ ]*TABLE[ ]*Info[ ]*("
$ cat input | grep -i "$var" | wc -l
3

This User Gave Thanks to balajesuri For This Post:
# 7  
Old 01-09-2012
thanks this might work :-) i hope there is no other option to directly make them space insenstive by using some options or regular expressions (i was trying to avoid manipulating the variable content so)... thanks anyway :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a particular string from column eliminating characters at the end.

Hi, So basically I have this file containing query output in seperated columns. In particular column I have the below strings: news news-prio I am trying to grep the string news without listing news-prio aswell. I tried grep "$MSG_TYPE" , grep -w "$MSG_TYPE" , grep... (4 Replies)
Discussion started by: nms
4 Replies

2. Solaris

ORA-00001: unique constraint violated

Am trying to install a account script in oracle 8i and I keep getting ORA-00001: unique constraint violated as the screen shot below shows so am wondering how do i fix this i have posted the full code that is the issue. i hope some one can help me, thanks a lot http://www.livve.com/sqlbug.jpg... (2 Replies)
Discussion started by: Wpgn
2 Replies

3. UNIX for Advanced & Expert Users

[SOLVED] LDAP Constraint Violation while changing password

Hello there, I hope that I am posting in the right section here, please advise if I posted wrong. I currently try to change passwords in our Active Directory Envoirenment via LDAP on Linux since the users in question do not have access to a windows-machine and we want to keep it that way. ... (0 Replies)
Discussion started by: henryford
0 Replies

4. Shell Programming and Scripting

awk: Eliminating white space while setting variable

Hi, I have a large flat file from host without delimiter. I'm transforming this file to a csv file using statements like # Row 03: Customer / field position 3059 +20 WOFABNAM=substr( $0, 3059, 20 ); and deleting the trailing whitespaces before and after with that sub( /^ +/, "",... (4 Replies)
Discussion started by: Celald
4 Replies

5. Shell Programming and Scripting

search and replace combination of two words...with a constraint

Hi I have 100 files in my directory. Please help me how to do in Unix or any other scriptin lanuages. I want to replace all occurances of "goutham" to goutham_ind ONLY if the file contains the word "goutham" with the word "engineer"; for eg----test1 is a file contains the following inf; goutham... (6 Replies)
Discussion started by: nandugo1
6 Replies

6. Shell Programming and Scripting

How to grep space?

Hi, I want to know how to grep space. Eg: input file contains 1565432 432 546 3514432 432 545 6541332 432 354 5464412 565 355 8456145 546 534 5632465 432 654 From this i need output of the lines which has 432 which are bold. My requirement is whenever 432 comes... (3 Replies)
Discussion started by: rakeshbharadwaj
3 Replies

7. Shell Programming and Scripting

Unique constraint violated within stored procedure executed from Perl

Hi! I got an strange trouble executing a stored procedures that goes inserting line by line on a table. I mus integrate it with perl for an specific task... the hole process is controlled by e Perl script that: Load a text file calling sqlldr. Call a stored procedure that process the... (2 Replies)
Discussion started by: jparra
2 Replies

8. AIX

Eliminating paging space and interpreting memory utilization

I just want to inquire on one of our DB Servers. Currently, we are running on 26GB of memory and 6 CPUs. Though our memory is 70-80 utilized, I can see some paging of around 8-10%. Is there any effective way we can lessen/eliminate paging? Here is our current VMO Settings: vmo: ... (1 Reply)
Discussion started by: depam
1 Replies
Login or Register to Ask a Question