how to use grep: finding a string with double quotes and multiple digits


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to use grep: finding a string with double quotes and multiple digits
# 1  
Old 01-17-2011
how to use grep: finding a string with double quotes and multiple digits

I have a file with a lot of lines (a lot!) that contain 10 digits between double quotes. ie "1726937489". The digits are random throughout, but always contain ten digits.

I can not for the life of me, (via scouring the internet and grep how-to manuals) figure out how to find this when I search. Smilie

I want to delete all of these eventually (not manually... or I'll be doing it until the next ice age) But I want to learn how to locate them first.

Does anyone have any suggestions? I'd appreciate it.

Thanks. Looking forward to learning a lot from this forum, and maybe I can help someone else out one of these days once I know what I'm doing.
# 2  
Old 01-17-2011
Code:
grep '"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"' inputfile

You can use the "-n" option to display the line number.

---------- Post updated at 06:07 PM ---------- Previous update was at 06:06 PM ----------

If you want to remove these lines:
Code:
grep -v '"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"' inputfile > outputfile

This User Gave Thanks to m.d.ludwig For This Post:
# 3  
Old 01-17-2011
If your grep supports -E (extended regex) then you can use
Code:
grep -E '"[0-9]{10}"' datafile

If not you will just have to repeat the char list 10 times:
Code:
gerp '"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"' datafile

If this is matching what you want, use the grep -v option to print all lines but those that match (in effect deleting the matching lines).
This User Gave Thanks to Chubler_XL For This Post:
# 4  
Old 01-17-2011
Excellent! This did the trick! I printed it to a new file without what I wanted... Thank you all so much. I'm adding this to my notes right now.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removal of multiple characters with in double quotes

For one of my need I was going through post "Removal of new line character in double quotes" Which alister has replied like $ cat data "leave me alone" "ABCD RENT-A- CAR XYZ LTD","00N0H","Enterprise Lake"," 100 View Way" $ sed -n 'H;g;/^*"*\("*"*\)*$/d; s/^\n//; y/\n/ /; p; s/.*//; h'... (9 Replies)
Discussion started by: Jag_1981
9 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

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

4. 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

5. Shell Programming and Scripting

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: "1017" Thank you! (5 Replies)
Discussion started by: esmgr
5 Replies

6. Shell Programming and Scripting

Multiple double quotes

hi Need to run below command on remote server: cmd -a "1 2" -b 3 If i run below, there's clash matching double quotes and fail. ssh $server "cmd -a "1 2" -b 3" I have few ideas which worked (like keeping the entire cmd in a file and copy it to remote server and then run that file)... (1 Reply)
Discussion started by: reddyr
1 Replies

7. UNIX for Dummies Questions & Answers

grep single quotes or double quotes

Unix superusers, I am new to unix but would like to learn more about grep. I am very familiar with regular expressions as i have used them for searching text files in windows based text editors. Since I am not very familiar with Unix, I dont understand when one should use GREP with the... (2 Replies)
Discussion started by: george_vandelet
2 Replies

8. Emergency UNIX and Linux Support

Grep expression between double quotes

I need a quick expression to be able to pull out all the data in a text file that looks like "http:// some random url etc" So it should grab any string that begins with "http:// and ends with " There are other double quotes in the file but I only want the ones that start with "http:// and the... (31 Replies)
Discussion started by: glev2005
31 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. Shell Programming and Scripting

Replace multiple blanks within double quotes

I have various column names within double quotes, separated by commas. Example: "column one", "column number two", "this is column number three", anothercolumn, yetanothercolumn I need to eliminate the double quotes and replace the blanks within the double quotes by underscores, giving: ... (5 Replies)
Discussion started by: jgrogan
5 Replies
Login or Register to Ask a Question