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.
the command works as:
s/<search regexp>/<replacement>/
so you need to search for :digitdigitspace and replace with :00 (including space at the end)
So instead of ^: at the end of your search expression:
s/:[0-5][0-9] /:00 / would be better (g is not required)
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
If you want to highlight your sentences just use bold or italic text, but not code.
I'm glad to help you.
Can you post a sample of the file wrapped in the code tags?
Are those spaces or tabs?
What version of sed are you using?
sycamorex, you hit the nail in the head. I've added CODE tags and they reveal the presence of TABs. Andreas H and pan64 you're kindly invited to use CODE tags in the future, for both the questions and the answers. Thank you.
Of course. But my general policy is to give the traditional explicit syntax for new scripters. Posting advanced shortcuts, at least without including detailed explanations of them, tends to confuse more than help. They also tend to be rather situation-specific and not easily adaptable to more generalized use.
More experienced users can usually figure out how to shorten it on their own.
For the record, the above code works because of the basic awk 'pattern { commands }' syntax. If you leave the bracketed commands off and only have a pattern, then it defaults to printing the line on a true evaluation. In this case, the sub function returns true when a valid substitution is made, and so the line prints.
Note though that because this relies on the status of sub to perform the action, if there happened to be any lines in the file that didn't contain a "$2" field, they wouldn't get printed. But the explicit declaration of the action in my version prints every line regardless of the substitution result.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.