ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
How to view the selected line number of the file. Mean i have the see the line numbers 1,4,8,12,16.....so on .
i can do with sed but can i do with cat or other simple command .
how can i select this thing in vi /vim editor.
Last edited by dina3e; 10-15-2008 at 10:55 AM.
Reason: Spell Mistake
Are you asking how to select a line number in vi? If so just type ":<line number> example ":10" displays line 10.
:10 works fine in vi editor , But i need to see the alternate lines or some line sequence like line No.1,3,6,9,12,15,...etc Then is there any option for this in vi/vim editor.
You can certainly do such things with awk, which has a programming language built-in.
In this case... the "pattern" that would be used is a dummy, that matches all lines. You use the awk-maintained record counter variable, and the "modulo" operator, to determine whether to print the current record.
It's well worth remembering that Unix/Linux is loaded with tools like this, and programming-languages like perl. It pays to fool around with them.
What exactly are you trying to achieve and why. It would make it easier for us to suggest appropriate answers/tools that way.
I suspect(!) that what you want is not possible in vi, but its not clear from your qn.
vi can only show you the contents of the file(s) you've opened. As said, you can go to any line, but if you only want to be able to see certain lines, you'd have to extract those lines and put them in another file.
You're welcome, dina3e, it's always nice to be appreciated here (or elsewhere); BUT you still didn't answer my Q about what you mean by "line sequence". Also, please do answer chrism01's Q about your goal -- he is right about us helping you better if we know where you want to go.
For those those who are wondering, sed -n '0~3p' & sed -n '1~3p' would display the arithmetic progression line sequences mentioned above.
As i like to work in vi/vim , so that i think is there any method available in vim that may process the filter's in the vim .
So that i asked such question & happy to get the answer.
I really Thank's to this forum from where i get lot of knowledge from other sites.
dwhitney67,
Can you do the every nth (arithmetic progression) thing in vim?
dina3e,
You still haven't answered my Q about whether it's really an arithmetic progression you are asking about. This is crucial to properly answering your Q.
2nd clarification: If all you want want to do is "view the selected line number of the file", why does it matter if you use sed or vim? Familiarity w/ one is not normally a good enough reason to shun the other. Is this part of a larger problem that you haven't mentioned? Please explain.
dina3e,
You still haven't answered my Q about whether it's really an arithmetic progression you are asking about. This is crucial to properly answering your Q.
2nd clarification: If all you want want to do is "view the selected line number of the file", why does it matter if you use sed or vim? Familiarity w/ one is not normally a good enough reason to shun the other. Is this part of a larger problem that you haven't mentioned? Please explain.[/quote]
you are correct . That does not matter if you use the vim/sed .
The arithmetic progression , mean let's i want to see the odd lines in vim . And there is no such problem also if i use sed .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.