Search string with invariable spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search string with invariable spaces
# 1  
Old 04-10-2009
Search string with invariable spaces

I need to grep for pattern "enable_cal = true".The problem is that different file has different no of spaces in that string.

for eg

one file will have "enable_cal <space><space><space>=true"
next file will have "enable_cal= <space><space>true"
other one will have "enable_ca<space><space>=<space><space>true"

Now I am seperately grep for each pattern.Plz help me here, I want a single grep that would only look for "enable_cal=true" provided how many spaces included between each word.
# 2  
Old 04-10-2009
is this what you want??
Code:
grep "enable_cal.*=.*true" filename

# 3  
Old 04-10-2009
Thanks dude.The code is working fine.
Thanks once again.
# 4  
Old 04-10-2009
Same flow another doubt

Just the continuation to where I left.

I just want to use grep to search for files that doesn't have 2 specific patterns "enable_cal=true" and "enable_cal=false"

I used the command below( grep -lv) is that correct

find ./ -name "cal_client.txt" | xargs grep -lv `enable_cal.*=.*false|enable_cal.*=.*true` > temp6.txt


But I am not getiing expected o/p.The expected output is 7 files only.But somehow I am getting 229 files.

Added details
==========
234 files total
202 files with pattern "enable_cal=false"
25 files with pattern "enable_cal=true"

I just want the pending 7 file names that doesn't has both the patterns.
# 5  
Old 04-10-2009
remove v from -lv because -v will return the names of the file in which pattern is not found.. refer grep man page
# 6  
Old 04-10-2009
If I remove -v option(with still -l option), I am getting an empty file.

Plz help me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Shell Programming and Scripting

Search for an undetermined number of spaces

I would like to find an undetermined number of spaces and shorten them to one space. I am running Debian in mksh. Script running in #!/bin/sh. Sorry to not include all code. The program is too big and involves an online file... too much hassle to solve a simple issue. Ex., I start with... (11 Replies)
Discussion started by: bedtime
11 Replies

3. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

4. AIX

Search a string having spaces

Hi I am looking to search a string having spaces in a directory for example : my string is "summer hot" my code :for i in `cat position__list.txt` do echo $i" : " `find . -mtime -6 | xargs grep -l ":83D:$i" | xargs ls -ltr|tail -1|awk '{ print $6 , $7 , $8, $9;... (6 Replies)
Discussion started by: wedng.bell
6 Replies

5. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

6. Shell Programming and Scripting

search pattern that has spaces with nawk

Hi guys, I need a help ! I need do grab some string from file and then count n lines after that pattern. This is working fine, but my problem is that the string to be searched has spaces within, like an example : LINK COUNTERS what I am using is: nawk... (2 Replies)
Discussion started by: robdcb
2 Replies

7. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

8. Shell Programming and Scripting

sed: replace string with another string (with spaces)

Hi I have an XML file with strings XABCD, XEFGHX and XIJKLX. I would like to replace XABCDX with "This is the first string", XEFGHX with "This is the second string" and XIJKLX with "This is the third string". What is the best way to implement this? Should I have a file with the data that is... (4 Replies)
Discussion started by: zmfcat1
4 Replies

9. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

10. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question