简体   繁体   中英

bash more effective use of sed / awk

I am looking for a more efficient to use the following string to get the desired result as a one liner

date -d @1381219358 | sed 's/\ \ /\ /g' | sed 's/[:\ ]/-/g' | sed 's/2013/13/' | awk -F '-' '{print $4"-"$5"-"$6"-"$2"-"$3"-"$8}'

The desired result output is as follows:

04-02-38-Oct-8-13

Any help would be appreciated

You can format the output directly, like this:

date -d @1381219358 +"%H-%M-%S-%b-%d-%y"
10-02-38-Oct-08-13

I'm not sure if you need sed or awk for this. You can format the output using date .

Try saying:

date -d @1381219358 +%H-%M-%S-%b-%d-%y

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM