Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi
I had opened a file in vim editor in my ubuntu 8.04 & wanted to see if line ends with \r\n (like DOS) or \r (in UNIX)
I tried
Code:
:%s/\n//gn
& vi editor got hung with processor nearing 50%
Then I pressed ctrl+c & vim resumed with message
Code:
147416605 matches on 1 line
So my question is
(1)why this reaction from vim ?
(2)I want to see al control characters in file . What should i do ?
I used notepad++ in windows & it had option to differentiate tabs,spaces,return etc.
it said the file was dos & for another different file it said unix
the question that remains is
(1)vim hangs on searching ?
(2)Is it possible to tell vim to show all characters i.e tab should be apparent without navigating to that position ?
Looking at your idea of "searching" .. you are applying a "replace" command and replace a line ending metacharacter with nothing. AFAIK, the replace command in vim will not change multiple lines into one, so this replacement is just without effect. You probably created an infinite loop, because it matches ALL THE TIME on the first line, not doing anything and starting again.
To just search (not replace), use the '/' command instead of ':s'.
For your question (2) -- no idea, never needed that
:%s/\n//gn
means % for all lines
g for counting multiple occurence in single line
'n' flag means no replacement just count matches
's' for substitution (occurs if 'n' flag absent)
:%s/\n//gn
'n' flag means no replacement just count matches
No it does not!!
From the OReilly Sed&AWK book (only the relevant part):
Quote:
s [address1[,address2]]s/pattern/replacement/[flags]
The following flags can be specified:
n Replace nth instance of /pattern/ on each addressed line. n is any number in the range 1 to 512, and the default is 1.
Normally a end-of-line character (\n, \n\r etc) only occurs once in a line (at the very end). Looking for it globally (the g switch) in that line is generally not needed.
BTW: if you only want to see if a certain string exists, why not use: /<string> ?
First of all: the n option is not sed specific, this flag has a different meaning when used with vim (as you mentioned in post #6). This n flag works when not using the end-of-line characters.
But, like I stated in my previous post, if you are only interested in seeing if these eol chars exists, why not use /\n (a normal search, which does work)?
I was actually counting number of occurences of \n in whole file.
You are right /\n will search the next newline but to count ex command is generally used
Last edited by sumeet inani; 07-27-2010 at 08:51 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.