LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep issue (https://www.linuxquestions.org/questions/linux-newbie-8/grep-issue-931523/)

eosbuddy 03-06-2012 02:11 AM

@jack_9: the examples I've given in my previous 2 posts are for literal "\t" - particularly the sed example (you can convert the 4 spaces (before the /g) to whatever else you'd like to be in there).

grail 03-06-2012 02:51 AM

Yeah I am still not with you :(

Using your example:

If we assume that the following returns "1 2 3 4 adlkjlfd;%114 \ttow\p felk&\t*"
Code:

rec=`sed -n "$j{p;q;}" ${file}`
So when we go to the grep line why can't we:
Code:

grep -x "${rec//\\/\\\\}" ${file}_dup

jack_9 03-06-2012 03:38 AM

Dunno :( Its not working.....



$ grep -x "${rec//\\/\\\\}" rec1
$ echo $?
1
$ echo "${rec//\\/\\\\}"
1 2 3 4 adlkjlfd;%114 \\ttow\\p felk&\\t*
$ echo $rec
1 2 3 4 adlkjlfd;%114 \ttow\p felk&\t*
$ cat rec1
1 2 3 4 adlkjlfd;%114 \ttow\p felk&\t*
$

grail 03-06-2012 04:24 AM

hmmm ... seems your -x on grep is putting you between a rock and a hard place. I think it is interpreting the \\ to be 2 slashes but when left as a single it thinks of \t
as a tab. I would add that without -x it works just fine.

jack_9 03-06-2012 05:01 AM

Yeah Grail.. you are correct.. the grep(in my unix box) is really poor..
And I did not find any other option except "-x" because I need to match the entire line..

If I wont give "-x" then, the half of line will also match, which wont give me the right result or pattern matching... I think you understood my point..

grail 03-06-2012 05:32 AM

You could put start and end, ie ^$, around the string but you actually have another issue to. It appears that the current solution also has an issue that the final asterisk is not
matched unless escaped. I must say I would wonder who in their right mind would have a database filled with this gibberish??

jack_9 03-06-2012 06:02 AM

Yeah, grail.. u r correct..
Finger crossed :)
Sybase database is also not very reliable in joins for such values(Like Space)

So, I wanted my script, should work on file level instead of database level..but in file level also I'm facing this issue..

I was happy with my Linux box and lots of options for grep and was able to do many stuffs..
However this unix box(and Sybase) is not allowing me to free up.. :(


All times are GMT -5. The time now is 11:38 PM.