Search for \n

Hi All,
How can i searc for a \n in a file. Not a newline but \n itself.

      In detail i have a statement printf\("\\n hello"\); here i need to find \\n. 

      Can u please help on this..

Thanks in advance

Regards,
Chanakya

A sed solution

sed -n -e '/\\n/p' in.txt

A grep solution is

grep -E '\\n' in.txt

To get a single \ you need to escape it.

Vino,
Thank a lot.. i got what i want. Can u explain me the command

  • Chanakya
sed -n -e '/\\n/p' in.txt

-n means do not print the lines that are read.
-e script to be executed.
'/\\n/p' For all lines that match the pattern containing \n, print it. We need the flag p to go with the -n option.
in.txt input file

grep -E '\\n' in.txt

-E consider the following expression as an extended regular expression.

In fact -E is not needed at all. You can drop it.

Thats fine.. I just tried the same in vi editor (s/\\n/g), could not find.. can u help me in this aspect

What are you trying to do ? Use the vi editor or an external tool ?

If it is the external tool, use the solutions I gave you.

If it is vi, then
/\\n
will show you all the occurences.

vino,
With ur explanation of ur sed expression i tried to replace \n with \r\n but i could not succeed. Have a glance at the command i used. Correct me.

sed -n -e 's/\\n/\\r\\n/p' ip.txt

output is not replacing all the \n. If a line have two '\n' then only first one is getting replaced.

if statement is printf("\nHello\n");

output is printf("\r\nHello\n");

expected printf("\r\nHello\r\n");

Can u help me on this

-Chanakya