ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I'm trying to write a little command line for loop that parses and acts on the contents of a file. The file is formatted like this:
<Unix time in seconds since 1970-01-01 00:00:00 UTC>,<one-digit-number>,<three-digit-number>
E.g:
1258747861,1,400
I want to display 1258747861 as you would if you used the command:
date --date=@1258747861 +"%F_%T"
I.e. 2009-11-20 20:11:01
Yet keep the last field (400) in-line in the output. So display:
2009-11-20_20:11:01 400
I don't want the lines containing '999' so i tried:
for entry in $(grep -v 999 Stats/ADSLStatus.csv | awk -F "," '{print $1" "$3}'); do set $entry; echo $1; done
I read that the 'set $entry' command should pass through the for loop once for each set of variables, rather than for each item, this way i hope to run date --date=@$1 +"%F_%T" and then echo $2 without further messing around with additional variable and awk.
However $1 seems to contain both the 1258747861 item and the 400 when i try to print it, and $2 is empty. I.e. the above command gives:
1258562761
220
1258724221
400
Instead of:
1258562761
1258724221
If anyone can suggest the best course of action to solve this it would be greatly appreciated. I bet it's quite straightforward, i just can't quite figure it out today.
It recognises IFS as ',' but read doesn't separate the input based on that. Instead, the first variable to read into reads the whole line of output from the command and replaces the ',' characters in it with spaces. The second and third variables are left blank.
Strange, 'cause this doesn't happen when files are used as input into the loop.
It recognises IFS as ',' but read doesn't separate the input based on that. Instead, the first variable to read into reads the whole line of output from the command and replaces the ',' characters in it with spaces. The second and third variables are left blank.
Strange, 'cause this doesn't happen when files are used as input into the loop.
Maybe the IFS is being used to parse the output from $(command). Try changing it to "$(command)"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.