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.
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 -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:
Code:
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 08: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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.