The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Search for a pattern from the result of search boopathi_d Shell Programming and Scripting 3 12-05-2007 09:54 AM
Search with $* GADO UNIX for Dummies Questions & Answers 2 11-19-2005 12:42 AM
Advanced Search Problems.. Search by User Name Neo Post Here to Contact Site Administrators and Moderators 1 05-19-2003 01:28 AM
Search using sed Ohji UNIX for Dummies Questions & Answers 1 08-14-2001 11:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-19-2006
Chanakya.m's Avatar
Chanakya.m Chanakya.m is offline
Registered User
  
 

Join Date: Jan 2006
Location: Bangalore, India
Posts: 55
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
  #2 (permalink)  
Old 07-19-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
A sed solution


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

A grep solution is


Code:
grep -E '\\n' in.txt

To get a single \ you need to escape it.

Last edited by vino; 07-19-2006 at 03:03 AM.. Reason: simpler solution...
  #3 (permalink)  
Old 07-19-2006
Chanakya.m's Avatar
Chanakya.m Chanakya.m is offline
Registered User
  
 

Join Date: Jan 2006
Location: Bangalore, India
Posts: 55
Vino,
Thank a lot.. i got what i want. Can u explain me the command

- Chanakya
  #4 (permalink)  
Old 07-19-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by Chanakya.m
Vino,
Thank a lot.. i got what i want. Can u explain me the command

- Chanakya

Code:
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


Code:
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.
  #5 (permalink)  
Old 07-19-2006
Chanakya.m's Avatar
Chanakya.m Chanakya.m is offline
Registered User
  
 

Join Date: Jan 2006
Location: Bangalore, India
Posts: 55
Thats fine.. I just tried the same in vi editor (s/\\n/g), could not find.. can u help me in this aspect
  #6 (permalink)  
Old 07-19-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0