How to handle backslash in grep string


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to handle backslash in grep string
# 1  
Old 06-18-2007
How to handle backslash in grep string

Hi ,
I am doing invert grep using -v but the string contain "/" which break the grep command and it do not skip the lines with "/" on it.
Diffu.txt
========
1159c1159
< <td align="right" valign="middle" class="paddingRight2px" id="featureListItemChannelButton7466">
---
> <td align="right" valign="middle" class="paddingRight2px" id="featureListItemChannelButton2505">
1168,1169c1168,1169
< document.getElementById( 'featureListItemChannelButton7466').innerHTML = '<img src="/images/buttons/playsm_disabled.gif" alt="Subscriber Only Channel" title="Subscriber Only Channel" class="playSm" border="0" height="20" width="20" \/><br \/><br class="v5" \/>';
< Element.addClassName( 'featureListItemChannelButton7466', 'contentUnAvail' );


DiffSkiplines.txt
===========
<td align="right" valign="middle" class="paddingRight2px" id="featureListItemChannelButton7466">
document.getElementById( 'featureListItemChannelButton7466').innerHTML = '<img src="/images/buttons/playsm_disabled.gif" alt="Subscriber Only Channel" title="Subscriber Only Channel" class="playSm" border="0" height="20" width="20" \/><br \/><br class="v5" \/>';
Element.addClassName( 'featureListItemChannelButton7466', 'contentUnAvail' );


cat /home/zabbix/public_html/diffu.txt| grep -v -f /home/zabbix/public_html/DiffSkipLines.txt returns

1159c1159
---
> <td align="right" valign="middle" class="paddingRight2px" id="featureListItemChannelButton2505">
1168,1169c1168,1169
< document.getElementById( 'featureListItemChannelButton7466').innerHTML = '<img src="/images/buttons/playsm_disabled.gif" alt="Subscriber Only Channel" title="Subscriber Only Channel" class="playSm" border="0" height="20" width="20" \/><br \/><br class="v5" \/>';

but it do not removes the line with document.getElement string as it has a backslash character before "/>".
Please let me know how to get rid of lines with backslash in it??


Regards,
Raj
# 2  
Old 06-18-2007
Don't cross post.

'\' is generic escape character in regular expressions.

Have you tried replacing "\" with "\\"

Last edited by porter; 06-18-2007 at 08:56 PM..
# 3  
Old 06-18-2007
how to do that??
# 4  
Old 06-18-2007
echo \\fred\\ | grep \\\\
# 5  
Old 06-18-2007
Can you explain with the two files which i have shown in the post?
# 6  
Old 06-18-2007
try replacing the line

Code:
title="Subscriber Only Channel" class="playSm" border="0" height="20" width="20" \/><br \/><br class="v5" \/>';

with

Code:
title="Subscriber Only Channel" class="playSm" border="0" height="20" width="20" \\/><br \\/><br class="v5" \\/>';

# 7  
Old 06-18-2007
Porter ,
Thanks i believe this will solve the problem until i come across any other issues..

Regards,
Raj
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add backslash and apostrophe to string in variable.

Hi All I want to add backslash and apostrophe to variable in my bash script. I have my variable: USER_LIST=USER1,USER2,USER3 and I want something like this: USER_LIST_DEL=/'USER1/',/'USER2/',/'USER3/' any ideas ?? (1 Reply)
Discussion started by: primo102
1 Replies

2. UNIX for Dummies Questions & Answers

Replace backslash at the end of the string using sed command

I have text file which is a tab delimited one. Sample data from the file is shown below: unix is\ great\ os linux\ is superb I want to replace that backslash with empty string preserving the tab delimiter. Output should be unix is great os linux is ... (3 Replies)
Discussion started by: p.akhilreddy4u
3 Replies

3. UNIX for Advanced & Expert Users

grep for a backslash question

Why does this work when grepping for a backslash? grep '\\' .bash_history grep "" .bash_historyWhy does this not work when grepping for a backslash? grep "\\" .bash_historyI know this works works but just don't understand why I need 4 backslashes when using double quotes. grep "\\\\"... (7 Replies)
Discussion started by: cokedude
7 Replies

4. UNIX for Dummies Questions & Answers

grep for a backslash as for loop parameter

Hello everyone, My main objective is to search for text within a file, namely a block of text where each line ends with a backslash "\". However, the block must begin with a keyword, like "loginstring". Here is an example of a file that contains a block: ############### loginstring \... (2 Replies)
Discussion started by: idlechatter
2 Replies

5. Shell Programming and Scripting

~R in between string, how to handle in AWK

Hi, Can any one help how to handle the below situation. Am using Awk script to handle variable When I open the file in VI mode, I see the string as Orange~Rs , but when I cat the file its showing as plain Oranges. When I copied the file over to Windows, am seeing the special character... (3 Replies)
Discussion started by: sp999
3 Replies

6. Shell Programming and Scripting

Cut on last backslash on hyperlink string-sed/awk??

hyper link- abc:8081/xyz/2.5.6/rtyp-2.5.6.jar Needs to get "rtyp-2.5.6.jar" i.e character after last backslash "/" how to do this using sed/awk?? help is highly appreciated. (7 Replies)
Discussion started by: kkscm
7 Replies

7. Shell Programming and Scripting

perl string matching problem (two backslash)

I have a few .tex files generated with html2latex. They have some extra \\ that generate error with pdflatex, so I would like to get rid of them. This perl -p -i -e s/\\\\//g myfile.tex with or without simple or double quote remove all of the backslashes, also the single ones needed by tex. How... (2 Replies)
Discussion started by: ahsog
2 Replies

8. UNIX for Dummies Questions & Answers

Grep alternative to handle large numbers of files

I am looking for a file with 'MCR0000000716214' in it. I tried the following command: grep MCR0000000716214 * The problem is that the folder I am searching in has over 87000 files and I am getting the following: bash: /bin/grep: Arg list too long Is there any command I can use that can... (6 Replies)
Discussion started by: runnerpaul
6 Replies

9. Shell Programming and Scripting

How ro handle backslash character in grep?

Hi , I am doing invert grep using -v but the string contain "/" which break the grep command and it do not skip the lines with "/" on it. Diffu.txt ======== 1159c1159 < <td align="right" valign="middle" class="paddingRight2px" id="featureListItemChannelButton7466"> --- > <td... (1 Reply)
Discussion started by: rajbal
1 Replies

10. UNIX for Dummies Questions & Answers

grep to handle a 0 result

Hi guys, I have the following grep command in a script to search through a file for a string and return its count, and it works fine for when the string exists: grep "string" file.txt | wc However, sometimes the result will be 0 and I want the script to take this as the result. Right now... (6 Replies)
Discussion started by: ocelot
6 Replies
Login or Register to Ask a Question