You don't need 5 posts to cut and paste sample data into a post (just like you did with your code). It looks like you're saying you have a file (in a very strange place unless you're running as root) that contains lines like:
depending on how long many days the machine has been up (where username, MM, DD, and YYYY are obvious and N is the last digit in the number of days the system has been running if the system has been up for more than 999 days). (Of course, your version of uptime may print something else in the 5 characters starting in position 15.)
And, this would mean the output from awk could be something like:
assuming you had collected 324 samples before you ran the script and that awk saw the last sample you added to the log using echo and head.
Note that the head in this script is a fairly expensive no-op. And, the awk can be replaced by a set and an echo.
I repeat. Please tell us in English what you are trying to do!
Show us sample input!
Show us desired output!
Keeping only the last 200 lines in your log file can be done by:
(assuming that you are running this in a directory that is on the same filesystem as /home).
If this is code being run by a normal user, I would have expected it to use $HOME/uplog.txt rather than /home/uplog.txt.
How is capturing 7 or 30 copies of the word day possibly mixed with dates of the form MM/DD/YYYY going to help you calculate average or total uptime? This makes no sense to me. PLEASE SHOW US SAMPLE DATA!
Last edited by Don Cragun; 06-16-2014 at 01:51 AM..
Reason: Fix sample output produced by your echo.
I have a file which is one big long line of text about 10Kb long.
Can someone provide a way using awk to introduce carriage returns every 40 chars in this file.
Any other solutions would also be welcome.
Thank you in advance. (5 Replies)
Hi there, I have a text file with several colums separated by "|;#" I need to search the file extracting all columns starting with the value of "1" or "2" saving in a separate file just the first 7 columns of each row maching the criteria, with replacement of the saparators in the nearly created... (4 Replies)
I have a file with 8 fields. I need the subtotals for fields 7 & 8 when field 5 changes.
cat wk1
01/02/2011/18AB/17/18/000000071/000000033
01/02/2011/18AB/17/18/000000164/000000021
01/02/2011/18AB/17/18/000000109/000000023
01/02/2011/28FB/04/04/000000000/000000000... (2 Replies)
Hi,
Here i have to check first record $3 $4 with second record $1 $2 respectively. If match found, then check first record $2 == second record $4 , if it equals , then reduce two records to single record like as desired output.
Input_file
1 1 2 1
2 1 3 1
3 1 4 1
3 1 3 2
desired... (3 Replies)
Hi,
how do i read a file using awk for a given no of line?
e.g
1. read only first 50 line.
2. read starting from line 20 to line 60..
thanks in advance.
-alva (8 Replies)
I want to count lines of a file using AWK (only) and not in the END part like this awk 'END{print FNR}' because I want to use it.
Does anyone know of a way?
Thanks a lot. (7 Replies)
Sorry for the weird title but i have the following problem.
We have several files which have between 10000 and about 500000 lines in them. From these files we want to remove lines which contain a pattern which is located in another file (around 20000 lines, all EAN codes). We also want to get... (28 Replies)
The output of an awk script is the below file. Line 1,3 that starts with the Ion... need to be under line 2,4 that starts with R_. The awk runs but no output results. Thank you :).
file
IonXpress_007 MEV37
R_2016_09_20_12_47_36_user_S5-00580-7-Medexome
IonXpress_007 MEV40... (6 Replies)
The awk below executes and is close (producing the first 4 columns in desired). However, when I add the sum of $7, I get nothing returned. Basically, I am trying to combine all the matching $4 in f1 and output them with the average of $7 in each match. Thank you :).
f1
... (2 Replies)