Difference between code page used with grep and vi


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Difference between code page used with grep and vi
# 1  
Old 12-14-2013
Difference between code page used with grep and vi

Not certain the title is phrased correctly but here's the issue:

I need to scrape data out of a pdf file. I ftp the file from windows to unix(solaris 10) as a binary file. Open the file in vi and search for a string, Matrix, but no joy. Then I cat the same file, pipe it to grep 'Matrix' and the string is found.

Can anyone explain this behavior and, perhaps, how to get vi to act the same as grep. BTW I did not try awk, perl or sed; yet anyway.

Thanks,
rj
# 2  
Old 12-14-2013
There are several possible reasons for this:

First, how did you issue the grep command? If it was "grep -i", then you switched on case INsensitivity, which is not so easily done in vi (certainly not with a command switch). Make sure you really search for the same string in both cases.

Second, The file might contain some (terminal-) control codes, which are "interpreted away" when you pipe it through cat.

Have a look at the unaltered file with "od -ax" to get even the non-displayable characters.

I hopoe this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 12-14-2013
Didn't use the "-i" switch with grep, nor the ":set ic" in vi but there are a bunch of non-printable characters in the file and maybe vi and cat/grep interpret them differently.

Thanks for the reply.
# 4  
Old 12-15-2013
As i thought more about this i had some more ideas:

You might find the places you find with cat | grep in vi using the following formula (given, its cumbersome, but good enough for learning more about the problem):

To search for "abc" interspersed with an arbitrary number of code-characters you can search for:

Code:
/a[^b]*b[^c]c/

You search for the first character, then an arbitrary number of the NOTted following character, then the following character itself and so on. This way you should catch occurrences of "abc" even if they are drowned in control codes. The only prerequisite would be that the string is still on one line no newline character in between).

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

IBM Code Page 437...

Hi all... Reference this URL: https://www.unix.com/unix-for-beginners-questions-and-answers/282400-lower-ascii-characters.html#post303037272 Researching in google for an answer showed the numerous times this has been asked for in various guises. So it inspired me to create a pseudo-IBM... (2 Replies)
Discussion started by: wisecracker
2 Replies

2. AIX

Code Page IBM-860

Helo all, I' trying to print Portuguese special characters like ç, ã, º, º . I already set my print queue for CODE PAGE of printer ibm.860 but every time i send a print test i receive the following error: 0782-059 Attribute name passed to subroutine piocmdout by program... (2 Replies)
Discussion started by: marques_rmc
2 Replies

3. Shell Programming and Scripting

Difference between 2 grep - commands

Hi, I need to know the difference between this commands: grep * *search* grep "*" *search* As far as i know does the 2nd command search for files which have a name with *search* and greps then all which have chars from a-z in the file content. But was does the first command?? Best... (1 Reply)
Discussion started by: xus
1 Replies

4. UNIX for Dummies Questions & Answers

Difference between grep, egrep & grep -i

Hi All, Please i need to know the difference between grep, egrep & grep -i when used to serach through a file. My platform is SunOS 5.9 & i'm using the korn shell. Regards, - divroro12 - (2 Replies)
Discussion started by: divroro12
2 Replies

5. Shell Programming and Scripting

Difference between '.*' and .* in grep

Hi What is the difference between grep '.*' xx and grep .* xx? What grep .* xx command will do where xx is file name. Thanks Sas (4 Replies)
Discussion started by: SasDutta
4 Replies

6. Shell Programming and Scripting

Getting source code of a page

I want to download a particular page from the internet and get the source code of the page in html format. I want to parse the source code to find a specific parameters using grep command. could someone tell me the linux command to download a specific page and parse the source code of it. ... (1 Reply)
Discussion started by: ahamed
1 Replies

7. UNIX Desktop Questions & Answers

Difference grep, egrep and fgrep

Hi All, Can anyone please explain me the difference between grep, egrep and fgrep with examples. I am new to unix environment.. Your help is highly appreciated. Regards, ravi (2 Replies)
Discussion started by: ravind27
2 Replies

8. UNIX for Dummies Questions & Answers

using Lynx and Grep to return search page rank - help

I am writing a script which will read in search terms from a text file and pass each line to Lynx. Lynx will grab the source html, then I want grep/tr, whatever to search for the first occurance of a term (mydomain.name), then delete from that 1st occurance on, creating a new end of file. Then... (0 Replies)
Discussion started by: roninuta
0 Replies

9. UNIX for Dummies Questions & Answers

What is the main difference between grep and sed

What is the main difference between grep and sed (1 Reply)
Discussion started by: ss4u
1 Replies

10. Shell Programming and Scripting

Code page in Unix

Hi, Can someone tell me how do I find the list of comptabile codepages on Linux(suse) , Is it /usr/lib/locale or somewhere else ? I was wandering if someone has expereince in using cycrillic chars (russian) in unix / linux ? Thanks (2 Replies)
Discussion started by: braindrain
2 Replies
Login or Register to Ask a Question