Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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 all, I made a C++ program in dos (in dev-C++) and uploaded it on Solaris box. On opening that file with 'vim' editor i found that there is some extra new lines after each written code line. I tried to find out is the file is in dos or in unix format, with 'file' command,and i got "<file-name>.h: ASCII C++ program text". After which i used 'dos2unix' command which shows 'converting file to unix format' but new-lines didn't disappear. Any help on this will be most welcome.
Its possible that if you saved it in vim, vim converted all the lines, so you've got double (Unix) new-lines.
Just upload from DOS and convert immediately before doing anything else.
Better yet, code on solaris in the first place (or any *nix).
To see what alien characters are appended to each line, post the result of
Code:
head <file-name>.h | od -c
then we can find a sed regexp to strip them out. As chrism01 already pointed out, download the file again and do the command above before any other attempt.
[xyz@blr api]$ head terminal.h.bak | od -c
0000000 / / * * * * * * * * * * * * * *
0000020 * * * * * * * * * * * * * * * *
*
0000120 * * * * * * \n \n / / N a
0000140 m e : T e r m i n a l . h \n \n
0000160 / / \n \n / / D e s c r i
0000200 p t i o n : T h i s f i l e
0000220 p r o v i d e s t h e d e
0000240 c l a r a t i o n o f t h e
0000260 T e r m i n a l o b j e c t
0000300 . \n \n / / \n \n
0000307
It confirms you have two consecutive newlines as Chris already guessed. Anyway, I'd do the tr command to strip them out or eventually a sed one-liner like
Code:
sed -i '/^$/d' file.h
but this actually removes all the blank lines. How do you think to remove some blank lines only and not other? Which is the criterium?
If criteria of deletion of new line we are talking about then it should be like deleting only one '\n' among repetition of it. Every Line in unix end with delimiter '\n' and if by any means, i'm getting one more blank line (mean one more '\n' entry) then i think any command that could delete only one '\n' among consecutive '\n' entries will be useful. Though, i'm not sure about it.
I've got the point. Anyway, a double \n\n equals to blank lines, so removing blank lines using sed should give you the result you want to achieve. For example try this:
Code:
sed '/^$/d' file.h | head | od -c
and see the difference with the previous output of od -c.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.