Home > Mobile >  extract date from a txt file using shell script
extract date from a txt file using shell script

Time:09-27

I have a file that has text value like below.

 ----------- 
| d_date      |
 ----------- 
| 2021-08-01|
 ----------- 

Need to set the date into a variable. Like d_date=2021-08-01 So, It can be used in a shell script. date_end=${d_date}

CodePudding user response:

Since you haven't given more information on the exact file format except that example:

date_end=$(tail -n 2 file.txt|head -n 1|tr -cd '[0-9-]')

(assuming that the input is stored in file.txt).

  • Related