Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GREP syntax 1

Status
Not open for further replies.

gbaughma

IS-IT--Management
Staff member
Nov 21, 2003
4,773
US
Hi there.

I have a CSV that I wish to run a GREP against. Unfortunately, all of the fields have double quotes around them... i.e.
"1000","12345","TEST","JOHN","ETC","SOME OTHER CRAP"... etc.

I need to search by the name, in this case John Test.

So, I'm sure this is simple, but I need to be able to grep something like "TEST","JOHN"

... and GREP "\"TEST\",\"JOHN\"" csvfilename.csv doesn't seem to be cutting it.... what am I doing wrong?

Thanks in advance!


Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
  • Thread starter
  • Moderator
  • #3
Hmm... I think I see what the problem is... the CSV file doesn't have a CRLF at the end of each line, looks like just CR... crap.... that's why if I *do* get a hit, it shows the entire file.



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Depending on your unix flavor, you should be able to do something like this (this is on Solaris)...
Code:
unix2dos myfile.csv | grep '"TEST","JOHN"'
 
unix2dos would convert LFs to CR/LFs. It sounds like the file in question is a Macintosh file if it has only CRs?

Annihilannic.
 
  • Thread starter
  • Moderator
  • #8
Nah... it came from an Alpha. I loaded it into WordPad then re-saved it, and it added the CRLF's so I can continue development. I talked to the admin of that box, and he said we'd come up with a work-around when I was ready to implement the script.

Many *nix boxes don't put CRLF, they only put the CR. Unfortunately, the DOS port of the GREP command that I'm using behind the script (because it takes FOREVER for ASP to sift through an 18 MB file looking for a string) wants CRLF as line terminators.

Problem evaded for the time being....


Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Err, no, Unix boxes nearly *all* only use LF (hex 0a). DOS uses CR/LF (hex 0d 0a). Macs used only CR (hex 0d)... but they may have changed recently with the more Unix-like OS X. I haven't used it, so can't say for sure.

Annihilannic.
 
If you need to swap the CR/LF with LF you can do it using perl like this.
Code:
# perl -i.bak -npe 's/\r\n/\n/g' [i]<filename>[/i]

M. Brooks
 
  • Thread starter
  • Moderator
  • #11
That's what I meant, about using LF instead of CRLF... but I said CR instead of LF...

Well, *I* understood that. ;)



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top