Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash get first word last line

Tags:

bash

changelog

I got a bash script and I started to write a changelog to keep track of changes.

I added in the script a function that echoes "Script version --> " But I have to manually edit it.

So I would need a function to get the first word until space of the last line and store it as $CURRENTVERSION

Changelog syntax is:

v-0.3.2 Added x, y.

v-0.3.2.1 Fixed y.

v-0.4 Added z.

Briefly I would need to store v-0.4 as $CURRENTVERSION

like image 448
Wyatt_LandWalker Avatar asked Feb 28 '26 09:02

Wyatt_LandWalker


1 Answers

Using awk:

awk '{w=$1} END{print w}' file

OR using sed:

sed -n '$s/^\([^ ]*\).*$/\1/p' file
like image 170
anubhava Avatar answered Mar 02 '26 14:03

anubhava