How to Fetch latest version form a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Fetch latest version form a file?
# 1  
Old 05-07-2018
Lightbulb How to Fetch latest version form a file?

Hi,

I have a file where versions will be updated, i need to get latest/last updated version from that file. Could you please help?
File looks like below -
Code:
 <versions>
      <version>R20180417.006</version>
      <version>R20180421.007</version>
      <version>R20180421.008</version>
      <version>R20180421.009</version>
      <version>R20180421.048</version>
      <version>R20180421.049</version>
      <version>R20180421.050</version>
      <version>R20180421.051</version>
      <version>R20180421.052</version>
      <version>R20180421.053</version>
      <version>R20180421.054</version>
</versions>


Last edited by vbe; 05-07-2018 at 11:37 AM.. Reason: code tags please
# 2  
Old 05-07-2018
Hello schandra128,

In case your latest version is always coming on 2nd last line of Input_file then following may help you on same.
Code:
tail -2 Input_file | head -1

Thanks,
R. Singh
# 3  
Old 05-07-2018
Code:
awk -F"[<>]" '$3 > version {version=$3} END {print version}' infile

This User Gave Thanks to rdrtx1 For This Post:
# 4  
Old 05-07-2018
Quote:
Originally Posted by RavinderSingh13
Hello schandra128,

In case your latest version is always coming on 2nd last line of Input_file then following may help you on same.
Code:
tail -2 Input_file | head -1

Thanks,
R. Singh
Thanks Ravinder for the response. but it will not be second line always actually. i just copied part of the file.
# 5  
Old 05-07-2018
Hello schandra128,

Following may help you on same.
Code:
awk -F">R|<" '{val=$3>prev?$3:prev;prev=$3} END{print val}' Input_file

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 6  
Old 05-07-2018
Quote:
Originally Posted by rdrtx1
Code:
awk -F"[<>]" '$3 > version {version=$3} END {print version}' infile

thank you for the response and solution, it worked Smilie

- Chandra
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetch the latest filename shell script

Hi I want to fetch the latest file form the list example example= filename RATE_STATE_SETUPS.20151222.ccyymmdd.hhmmss.txt File pick which have latest ccyymmdd.hhmmss list of file in directory are RATE_STATE_SETUPS.20151222.20151222.170101.txt... (5 Replies)
Discussion started by: MOHANP12
5 Replies

2. UNIX for Dummies Questions & Answers

Finding Oracle form Version UNIX

I'm trying to find the version of the underlying Oracle forms from out Unix Server. I have tried frmcmp.sh -h but I get the error frmcmp.sh -h : not found Its a Unix Sun server running an oracle database Any ideas? (1 Reply)
Discussion started by: dbajtr
1 Replies

3. UNIX for Advanced & Expert Users

Need commands to fetch Guest VM OS version from Xen and KVM

Im looking for the commands that can be executed to fetch the OS Version of the VMs running on the below Hypervisors. Xen (Not the citrix Xen server, but the Xen Sever hosted on a ubuntu Machine) KVM (0 Replies)
Discussion started by: ranvirsingh
0 Replies

4. Shell Programming and Scripting

Help with finding the latest modified version of a file within directories

I am trying to look into multiple directories and pluck out the latest version of a specific file, regardless of where it sits within the directory structure. Ex: The file is a .xls file and could have a depth within the directory of anywhere from 1-5 Working directory - Folder1... (6 Replies)
Discussion started by: co21ss
6 Replies

5. AIX

Latest firmware version for P770

Dears i have a power7 P770 working in AIX 5.3 TL 11 with frimware AM730_066 is the AM730_066 frimware the latest one or not ? (6 Replies)
Discussion started by: thecobra151
6 Replies

6. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

7. BSD

latest version of bsd

Any body there ? What is latest BSD version ? (4 Replies)
Discussion started by: chilaka
4 Replies

8. Shell Programming and Scripting

search latest version of log file

Have checked the forums and couldnt locate help on this. I want to grep a log file for a pattern using a script - I need to grep the latest log file and not sure how I am able to ensure I am greping the latest log file. Here is sample of log files for yestersday and I effectively need to grep... (10 Replies)
Discussion started by: frustrated1
10 Replies

9. Shell Programming and Scripting

Latest version of a file across the servers ..

:o How do I confirm that the script on one server is latest compare to other servers? Is there any script which can tell me the latest version of a file across the servers? Thanks, (2 Replies)
Discussion started by: Sandy
2 Replies

10. UNIX for Dummies Questions & Answers

What is the latest version of Unix?

I want to buy it (2 Replies)
Discussion started by: LANSTARR.COM
2 Replies
Login or Register to Ask a Question