How to insert tab at specified column.HELP

I have input like:
1234567890

cut -c1-3,6-7,9-10 input > output

Now I got 1236790.

I want to insert space between each cut. So the output like:
123 67 90

Can anybody help?
Thanks.

One way to add spaces (not a tab or "\t" character):

awk '{print substr($0,1,3), substr($0,6,2), substr($0, 9,2)  }' > output

Is there other way using other UNIX command? awk is not working for me.
giving me "16 bit MS-DOS Subsystem" error message. :confused:

Hi.

This is one alternative using GNU cut:

#!/usr/bin/env sh

# @(#) s1       Demonstrate insertion of string for cut output fields.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions of codes used in this script -- local code \"version\")"
version bash cut

echo
echo " Expecting |123 67 90|"

echo "1234567890" |
cut -c1-3,6-7,9-10 --output-delimiter=" "

exit 0

Producing:

% ./s1

(Versions of codes used in this script -- local code "version")
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
cut (coreutils) 5.2.1

 Expecting |123 67 90|
123 67 90

See man pages for details ... cheers, drl

:slight_smile:
Thank you drl. You are so helpful.

What if two field being cut are next to each other, the delimiter will not be inserted?
cut -c1-3,4-5 --output-delimiter="|" input > output
The output will be:
12345

How to get 123|45?

Another question is how to get rid of the leading space, if I have input like:
1234567890
I'd like to have output
123|45
instead of
123|45

Could you please help?
Thanks.

Oops.
input: | 123456789|
output:|123|45|

no leading or tailing space in every field.

Hi.

If cut by itself will not work properly, then one could use:

#!/usr/bin/env sh

# @(#) s4       Demonstrate insertion of string for cut output fields.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions of codes used in this script -- local code \"version\")"
version bash cut paste

echo

echo "  1234567890  " >data0

echo " Input data (ends marked with \":\"):"
sed -e 's+^+:+' -e 's+$+:+' data0

sed -e 's|^  *||' -e 's|  *$||' data0 >data1

echo
echo " Expecting |123|45|90|"

cut -c1-3 data1 >t1
cut -c4-5 data1 >t2
cut -c9-10 data1 >t3

paste -d"|" t1 t2 t3 |
sed -e 's+^+|+' -e 's+$+|+'

exit 0

Producing (modified in place for this output):

% ./s4

(Versions of codes used in this script -- local code "version")
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
cut (coreutils) 5.2.1
paste (coreutils) 5.2.1

 Input data (ends marked with ":"):
:  1234567890  :

 Expecting |123|45|90|
|123|45|90|

See man pages for details ... cheers, drl