How to find a string with double quotes?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find a string with double quotes?
# 1  
Old 05-22-2013
How to find a string with double quotes?

I have thousands of files in a directory. I need to find/list all files that have the below matching string -

RETURNCODE:[4] "1017"


Thank you!
# 2  
Old 05-22-2013
grep?
Code:
grep 'RETURNCODE:[4] "1017"' *

Just how many files?
# 3  
Old 05-22-2013
Scott, I guess the square bracket need to be escaped, isn't that right?

Also since OP is interested in file names with matching pattern, -l option can be used:
Code:
grep -l 'RETURNCODE:\[4\] "1017"' *

This User Gave Thanks to Yoda For This Post:
# 4  
Old 05-22-2013
If you mean that you want to list files in the directory that contain this string, try:
Code:
grep -Fl 'RETURNCODE:[4] "1017"' *

or if that gives you a complaint about an argument list that is too long:
Code:
find . ! -name "." -prune -type f -exec grep -Fl 'RETURNCODE:[4] "1017"' {} +

# 5  
Old 05-22-2013
Quote:
Originally Posted by Yoda
Scott, I guess the square bracket need to be escaped, isn't that right?

Also since OP is interested in file names with matching pattern, -l option can be used:
Code:
grep -l 'RETURNCODE:\[4\] "1017"' *

Yes, I should have used fast grep or escapes which, had I bothered to test I'd have seen Smilie

Last edited by Scott; 05-22-2013 at 03:00 PM.. Reason: Edited to more accurately reflect the truth!
This User Gave Thanks to Scott For This Post:
# 6  
Old 05-22-2013
Quote:
Originally Posted by Scott
grep?
Code:
grep 'RETURNCODE:[4] "1017"' *

Just how many files?
Scott,
I don't think this will work. The grep utility (unless invoked as grep -F or fgrep) treats the search string as an basic regular expression; not as a string. So [4]in the expression will match 4 instead of [4]. When grep is invoked with the -F option, the search string is treated as a fixed string instead of as a BRE. (The current standards don't mention fgrep, but historically, fgrep was a hard link to grep and when grep saw that it was invoked as fgrep it acted as if it had been invoked with what the standards now specify as the -F option.)
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace double quotes inside the string data for all the columns

Please use code tags Hi, I have input data is below format and n of column in the multiple flat files. the string data has any double quotes(") values replaced to double double quotes for all the columns{""). Also, my input flat file each column string data has carriage of new line too.... (14 Replies)
Discussion started by: SSrini
14 Replies

2. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

3. Shell Programming and Scripting

awk to find and replace Double quotes between pipes

Hello, Need a AWK command to find and replace Double Quotes in Pipe delimited files Actully its a CSV file converted to Pipe but the double quotes still exists. So i want to Get rid of them. Example Input 1|2|3|sadsad|"Abc Efg 3"""|dada Output 1|2|3|sadsad|Abc Efg 3"|dada Thanks... (5 Replies)
Discussion started by: krux_rap
5 Replies

4. Shell Programming and Scripting

Adding double quotes at the end of string

My input is this: Inputfile = file.txt needs to change to, Inputfile = file.txt" I have tried using: Inputfile = `echo ${Inputfile}"' doesn't work for me. Similarly how do I change it to all double quotes: Inputfile = "file.txt" (4 Replies)
Discussion started by: bvnprasad123
4 Replies

5. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

6. Shell Programming and Scripting

Use double quotes as part of the string in a Bash array

So I need to create an array that has " in the string of the text: string = ( "value 1" "value2" where the actual string is "value1" with the quotations included would this work? string = ( \"value1\" \"value\") and if the strings contain spaces as well: string = ("\"this... (4 Replies)
Discussion started by: os2mac
4 Replies

7. Shell Programming and Scripting

How to remove extra double quotes from string in a delimited file??

Hi Unix Gurus.. I am new to Unix. Please help me. The file I am getting is as follows: Input File "2011-07-06 03:53:23","0","I","NOT SET ",,,,"123985","SAW CUT CONCRETE SLAB 20"THICK",,"98.57","","EACH","N" "2011-07-06 03:53:23","0","I","NOT SET ",,,,"204312","ARMAFLEX-1 3/8 X... (2 Replies)
Discussion started by: BICC
2 Replies

8. Shell Programming and Scripting

how to find the count of commas in a string excluding the ones in double quotes

Hi, my requirement is to find the count of commas in a string excluding the ones in double quotes. For example: If the input string is abc,xyz.com,lmhgdf,"abc, 401 street","tty,stt",45,23,45 The output should be 7 (7 Replies)
Discussion started by: amitshete
7 Replies

9. Shell Programming and Scripting

Add double quotes around the string

I have a line in multiple scripts:select into table /dir1/dir2/file.dat dir1 and dir2 are the same but file.dat is different from script to script. I need to include /dir1/dir2/file.dat into double quotes in each file of my directory:select into table "/dir1/dir2/file.dat" (13 Replies)
Discussion started by: surfer515
13 Replies

10. UNIX for Dummies Questions & Answers

grep exclude/find single and double quotes

Hello, I'm trying to use grep or egrep to exclude a whole range of characters but how do I exclude both a single and a double quote. It might be easier to say how do I use grep to find both single and double quotes. grep ' ' " ' file grep detects the first single quote within my... (4 Replies)
Discussion started by: Lindy_so
4 Replies
Login or Register to Ask a Question