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.
For part 1 (this is at least 2x as fast as using Perl, use the 'time' program to check for yourself):
Code:
cut -b 9-12 NewFile
output is:
Code:
1217
0404
0254
For part 2 (haven't tested speed of this vs Perl, because I don't know Perl, this time my money is on Perl, but I could write a small C program to do this and it will be faster):
Not checked for timing, but this other one-liner does all
Code:
gawk -F\; '{print $2}' myfile | date -f- +"%b %d"
thx reply ,
I tried the script , but it do not find the FIRST line of the line , what I want to get is the date in FIRST line , the second ,if the file format is as below , the 1200 is the time , can advise how to modify the script to get the same result ? Thx in advance.
I tried the script , but it do not find the FIRST line of the line , what I want to get is the date in FIRST line , the second ,if the file format is as below
Sorry, but I don't truly understand what you're saying: did you get an error when processing the first line of your file?
Regarding you're last example, you can simply extract a substring from the second field, like this
Code:
gawk -F\; '{print substr($2,1,8)}' myfile | date -f- +"%b %d"
Anyway you will get an error when processing the LAST line of your example, since the 54th of February has not been added to the calendar, yet!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.