I am writing a bash script that connects to a server, exports data to a .csv file and then runs a jar that uses that newly created file. The problem is, the jar requires the file name to include the value of the Timestamp column of the first row in the .csv file.
Here is the first line of my .csv file. In this case, the timestamp is 2012-11-01 located at the end of the row.
"####<Nov 1, 2012 12:00:01 AM UTC> <Warning> <AesoRMQAdapter::RabbitMQAdapter> <> <myServer> <[ACTIVE] ExecuteThread: '7' for queue: 'weblogic.kernel.Default (self-tuning)'> <> <> <> <1351728001726> <BEA-000000> <DEBUG SEND MESSAGE={"Volume":55.1,"OfferedVolume":54.8,"ArmedVolume":0.0,"Status":false,"BlockNr":0,"Timestamp":"2012-11-01T00:00:01+0000"}> "
My question is as followed.
How can I, after retrieving the .csv file…
- Grab the first timestamp from the first row in the .csv file
- Use that timestamp in a filename that I’ll be saving the .csv file under
I appreciate all of your help!
Use
head -1to get only one line from your input file, thengrep -oto retrieve all timestamps in this line thenhead -1to keep only the first one.