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 -

 <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>

Hello schandra128,

In case your latest version is always coming on 2nd last line of Input_file then following may help you on same.

tail -2 Input_file | head -1

Thanks,
R. Singh

awk -F"[<>]" '$3 > version {version=$3} END {print version}' infile
1 Like

Thanks Ravinder for the response. but it will not be second line always actually. i just copied part of the file.

Hello schandra128,

Following may help you on same.

awk -F">R|<" '{val=$3>prev?$3:prev;prev=$3} END{print val}' Input_file

Thanks,
R. Singh

1 Like

thank you for the response and solution, it worked :slight_smile:

  • Chandra