Solved How to split 10 charaters to 5x2

March 5, 2013 at 19:11:30
Specs: AIX
I need to split a string (10characters)

0123456789

to

01 23 45 67 89

and change to

89 01 23 45 67


thanks


Mamba


See More: How to split 10 charaters to 5x2

Report •

#1
March 6, 2013 at 06:44:15
✔ Best Answer
One way is to use the cut command's -c option. I'll do part and I'll let you do the other part:

#!/bin/ksh

str="0123456789"
f1=$(echo $str|cut -c1-2)
f2=$(echo $str|cut -c3-4)

echo $f1
echo $f2

echo "$f1 $f2"


Report •

#2
March 6, 2013 at 18:44:08
looks good, but i forgot that those 10 digits are in line other information so by testing

| fold -w 2
01
23
45
67
89

wasnt helpfull ,also not

$ echo 1234567890 | sed 's/../& /g'
12 34 56 78 90

so i used evil sed

| sed 's/\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)/20\5\/\1\/\2 \3:\4 /g'

to change the date/time to normal output


$ errpt | head -5
IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION
5A7598C3 0306045113 I O fscsi3 Additional FC SCSI Protocol Driver Infor
5A7598C3 0306045013 I O fscsi3 Additional FC SCSI Protocol Driver Infor
5A7598C3 0306045013 I O fscsi3 Additional FC SCSI Protocol Driver Infor
5A7598C3 0306045013 I O fscsi3 Additional FC SCSI Protocol Driver Infor
$

$ errpt | head -5 | sed 's/\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)/20\5\/\1\/\2 \3:\4 /g'
IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION
5A7598C3 2013/03/06 04:51 I O fscsi3 Additional FC SCSI Protocol Driver Infor
5A7598C3 2013/03/06 04:50 I O fscsi3 Additional FC SCSI Protocol Driver Infor
5A7598C3 2013/03/06 04:50 I O fscsi3 Additional FC SCSI Protocol Driver Infor
5A7598C3 2013/03/06 04:50 I O fscsi3 Additional FC SCSI Protocol Driver Infor
$

sed 's/\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)/

parser part

20\5\/\1\/\2 \3:\4 /g'

20 just text, begining of year and the
\5 is 89
\/ is /
\1 is 01
\/ again /
\2 is 23
\3 is 45
: is :
\4 is 67

so from 0123456789 i got 2089/01/23 45:67


Report •
Related Solutions


Ask Question