Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
The -F tells it to use colon ( as the field separator. The print then says to print out "??:" (a literal string) followed by the second field (minutes) a colon (another string) and finally the third field (seconds).
Since hours is the first field you don't print it at all - you just print the first literal string noted above.
filename of course is the name of the file that contains your times.
Assuming all your records are like the above (that is the time never occurs at the beginning of a line and always has a space before it then doing the following will work:
sed 's/ ..:/ ??:/g' filename
Notice in the above there is a space after the first slash (/) and before the two dots (..) and also a space after the second slash (/) and before the two question marks (??). This is essentially the same syntax you were given earlier but the spaces are there to make them part of the pattern and also "g" has been added after the third slash (/). The "g" tells it to do the change globally rather than just on the fist occurence.
You could also adapt the awk syntax I gave earlier but given your line I think the sed is probably a better way to go in this case.
FYI: In my opinion awk has more power because it has a full programming capability but for simple text manipulation its probably more correct to say that its a matter of preference than absolutes.
Last edited by MensaWater; 11-29-2005 at 09:46 AM.
you can write a sed script to make multiple commands easier to follow--other wise prefix every command with "-e" (see the manual)
Your file has some unique patterns: Try this:
sed -e 's/[A-Z]200./ ,20xx/' -e 's/,200./ ,20xx/' < file > newfile
The first expression after -e looks for the year preceded by any capital letter
The second expression looks for the year preceded by a comma
Note the quotes required because there are spaces in the expressions
Try this on your file and then go read one of the tutorials---including learning regular expressions. I recommend a good book on scripting, also.