0

The following table is the mysql database table(i.e select * from users) I want the last updated time row using linux command?

+------------+----------+---------+--------------+--------------+-----------+--------------+--------+------+--------------+
| time       | userid   | groupid | jobs_running | jobs_pending | job_limit | 
+------------+----------+---------+--------------+--------------+-----------+--------------+--------+------+--------------+
| 1476274005 | achandra |         |            4 |            0 |         0 |            
| 1476274793 | akawle   |         |           52 |           48 |         0 |     
| 1476274793 | awle     |         |           56 |           49 |         0 |    
| 1476274799 | awlnbkle |         |           59 |           67 |         0 |  

Expected Output:

| 1476274793 | akawle   |         |           52 |           48 |         0 |     
| 1476274793 | awle     |         |           56 |           49 |         0 |    
| 1476274799 | awlnbkle |         |           59 |           67 |         0 |  
kenorb
  • 20,250
  • 14
  • 140
  • 164
gps sago
  • 111
  • 1
  • 1
  • 6
  • Possible duplicate of http://unix.stackexchange.com/questions/48777/command-to-display-first-few-and-last-few-lines-of-a-file – Valentin B. Oct 19 '16 at 08:42
  • Your edit is nice, but how do you determine the number of rows to output ? Do you compare the `time` column value with a reference ? Do you want those rows to be printed in terminal dynamically (everytime the table is appended) or to be able to run a command once in a while to extract those values ? – Valentin B. Oct 19 '16 at 08:49
  • Also you should add the `/text-processing` tag in your next edit. – Valentin B. Oct 19 '16 at 08:52
  • Rows to printed dynamically when the table is appended everytime.I had used (i.e $current_time=`date +%s`).But this does not shows my expect output because it display all timings .But i need the last recent updated time which i mentioned in the expected output. – gps sago Oct 19 '16 at 08:53

2 Answers2

0
tail -n 1 input.txt

Check man tail for more detail on the command. This command simply displays the last line of the file.


EDIT Considering the information you added, you might to try this:

tail -f -n 0 input_file.txt

The -f (for follow) means that everytime some data is added in input_file.txt, it will be outputed to the terminal where you are running that command. -n 0 is here so that when you run the command, you display nothing and only consecutive appended lines will be displayed.

Valentin B.
  • 775
  • 5
  • 18
0
your_command | sort -rn | head -n 1

Since the most recent time must be the maximum value

If your_command is mysql, you should also use -B for it, in order to obtain tab seperated output instead of bars.

LittleSmurfie
  • 337
  • 1
  • 6