0

i have a list that contain data in the format(year-month-day-hrmn-00S.GHTUJ_035)

2017-01-22-1522-00S.GHTUJ_035
2016-12-21-1725-00S.GHTUJ_035
2019-11-25-1123-00S.GHTUJ_035
2015-09-25-1329-00S.GHTUJ_035

Now i want to convert year-month-day portion of the data to julianday and want to paste it in its right side. so my expected output should be

2017-01-22-1522-00S.GHTUJ_035   022
2016-12-21-1725-00S.GHTUJ_035   ...
2019-11-25-1123-00S.GHTUJ_035   329
2015-09-25-1329-00S.GHTUJ_035   ...

i am able to write only half part of the script so i need experts help.Thanks in advance.

while read line;
do
echo $line
done< list

1 Answers1

1

datepart=${line%-[0-9][0-9][0-9][0-9]-00S*} will give you the date part of your string and you can use date +%j -d $datepart to convert it to julian.

${line%-[0-9][0-9][0-9][0-9]-00S*} is bash syntax for take $line and remove everything (that is what % means) from -, four digits, another - and 00S up to the end of the string (the *).

date -d allows you to give a specific date to perform the actions on. The +%j tells date what output it should give. See man dae for details and more options.

Ljm Dullaart
  • 4,273
  • 2
  • 14
  • 31
  • This is not julian day, but day of year – kvantour Nov 23 '20 at 16:12
  • 1
    In computer programming, the meaning of Julian date changes sometimes. Julian date is considered to be the number of elapsed days since the beginning of a particular year. Which matches by the way exactly the OP's required output. It is not a coincidence that date uses the letter `j` for this format. – Ljm Dullaart Nov 23 '20 at 16:17
  • Okay, I had no clue! Upvote for learning something here – kvantour Nov 23 '20 at 16:18