Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Time From Multiple Lines of Data 2

Status
Not open for further replies.

thunderkid

Technical User
Oct 26, 2000
54
US
I would like to extract time from last records from data set shown below:

input
abc 0:01:10.0 rtyh jdkrd
abc 0:01:30.0 rtyh jdkrd
abc 0:01:60.0 rtyh jdkrd
abc 0:02:10.0 rtyh jdkrd
abc 0:03:00.0 rtyh jdkrd

desired output
abc 0:03:00.0 rtyh jdkrd

Tahnks
 
tail -1 input

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Sorry for not explaining the whole context for this task. There are thousands of line within the files and I will have to make multiple extractions. For example:

nput
abc 0:01:10.0 rtyh jdkrd
abc 0:01:30.0 rtyh jdkrd
abc 0:01:60.0 rtyh jdkrd
abc 0:02:10.0 rtyh jdkrd
abc 0:03:00.0 rtyh jdkrd
def 0:03:01.0 erte wfe5
def 0:04:10.0 erte wfe5
def 0:05:01.0 erte wfe5
def 0:05:30.0 erte wfe5
def 0:06:03.0 erte wfe5
.
.
.

desired output
abc 0:03:00.0 rtyh jdkrd
def 0:06:03.0 erte wfe5
.
.
.
 
Try and adapt the following code :
[tt]
awk '
$1 != prv1 { if (last_line != &quot;&quot;) print last_line }
{ prv1 = $1; last_line = $0 }
END { if (last_line != &quot;&quot;) print last_line }
' input_file
[/tt]


Jean Pierre.
 
nawk '
{ a[$1]=$0 }
END {
for (i in a)
print a;
}
' input

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thank you aigles
Thank you vlad
Both solutions worked.

thunderkid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top