how to remove comment lines (as # bal bla ) and empty lines (lines without charecters) from file with one sed command?
THX
lidia
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re worried about starting two
sedprocesses in a pipeline for performance reasons, you probably shouldn’t be, it’s still very efficient. But based on your comment that you want to do in-place editing, you can still do that with distinct commands (sedcommands rather than invocations ofseditself).You can either use multiple
-earguments or separate commands with a semicolon, something like (just one of these, not both):The following transcript shows this in action:
Note how the file is modified in-place even with two
-eoptions. You can see that both commands are executed on each line. The line with a comment first has the comment removed then all is removed because it’s empty.In addition, the original empty line is also removed.