How to get a command to run through each line of text
Hi, just wondering can anyone tell me what is the appropriate way to get a line of code to run through each line, I know you have to pipe the file with the code but am having trouble with it. Here is a sample from the text (it has alot of lines!) I want to convert and the code to do it (would take ages to do line by line)
2009-10-01 02:53:07 2009-10-01 05:00:01 2009-10-01 07:59:09 2009-10-01 08:02:22 2009-10-01 08:05:57 2009-10-01 08:05:57 2009-10-01 08:05:57 2009-10-01 08:06:08 2009-10-01 08:06:08 2009-10-01 08:06:17 #! /bin/sh dateandtime=`echo "datestime.txt" |date -d "2009-10-09 08:39:59" +%s Output will be like 1255073999 I am not sure how to get it to read through each line? Any ideas anybody has would be appreciated! |
I'm sure one should use xargs, but my immediate way would be...
for i in $(cat file) do dateandtime=$(date -d "$i" +%s) done don't use backticks btw, use $(...) instead. Ahh, xargs... xargs -a file -I XXX date -d XXX +"XXX is %s as a unix timestamp" |
Thanks acid kewpie, xargs was a much simpler command to output the time to UTC :)
|
xargs is a command that's been a bit of a nemesis for a while now, finally forcing myself to try to understand and use it instead of a million for loops.
|
Quote:
Bash programming doesn't have to look like crap -- that's optional and at the discretion of the programmer: Code:
for ((y = 1;y <= 12;y++)) Code:
1 2 3 4 5 6 7 8 9 10 11 12 |
All times are GMT -5. The time now is 07:33 AM. |