423,323 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,323 IT Pros & Developers. It's quick & easy.

Formatting string output in bash

Expert 100+
P: 921
Is there a more elegant way to do this:
Expand|Select|Wrap|Line Numbers
  1. mktemp -u XXXXXXXXXXXXXXXX | sed 's/\(....\)\(....\)\(....\)\(....\)/\1-\2-\3-\4/g'
This will output 16 characters with '-' signs between the output like (i.e.): EjSe-Cla4-OaT7-IR26
Aug 19 '17 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 921
Ok, I did find two alternative to do this:
Expand|Select|Wrap|Line Numbers
  1. s=; for (( i=1; i<=4; i++ )) ; do s=$s-`mktemp -u XXXX` ; done; echo ${s:1}
  2.  
and
Expand|Select|Wrap|Line Numbers
  1. function abc () { mktemp -u XXXX; }; echo `abc`-`abc`-`abc`-`abc`
  2.  
But the sed part in my original attempt...
Can I be written simpler?
Aug 19 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.