f



add a dot after each char of a string

Hello
I would like to add a dot after each char of a string.

Example:

ciao

c.i.a.o

I tried :

echo "ciao" | awk '{print $0 "."}' FS=""

And it returns:
ciao.

Thanx for help


0
sinapsi
10/12/2003 3:55:04 PM
comp.unix.shell 15484 articles. 3 followers. Post Follow

5 Replies
264 Views

Similar Articles

[PageSpeed] 3

> [ add a dot after each char ]

Try:
echo text | sed 's/./&\./g'


0
bigcheese
10/12/2003 4:03:13 PM
sinapsi wrote:
> I would like to add a dot after each char of a string.
>
> Example:
>
> ciao
>
> c.i.a.o
>
> I tried :
>
> echo "ciao" | awk '{print $0 "."}' FS=""

$ echo ciao | sed 's/./&./g'
c.i.a.o.
$ echo ciao | sed 's/./.&/g;s/.//'
c.i.a.o
$ echo ciao | fold -w1 | paste -sd.
c.i.a.o
$ echo ciao | gawk '{$1=$1}1' FS= OFS=.
c.i.a.o

-- 
St�phane
0
Stephane
10/12/2003 4:36:48 PM
"sinapsi" <info@zam.it> wrote in message news:<sPeib.271080$R32.8827022@news2.tin.it>...
> Hello
> I would like to add a dot after each char of a string.
> 
> Example:
> 
> ciao
> 
> c.i.a.o
> 
> I tried :
> 
> echo "ciao" | awk '{print $0 "."}' FS=""
> 
> And it returns:
> ciao.


echo "ciao" | perl -le 'print+join".",split//'
0
sharma__r
10/13/2003 5:09:51 AM
rakesh sharma wrote:
[...]
> echo "ciao" | perl -le 'print+join".",split//'

echo ciao | perl -F// '-lape$_=join".",@F'

z=ciao zsh -c '<<<${${z///.}#?}'

-- 
St�phane
0
Stephane
10/13/2003 12:37:03 PM
Stephane CHAZELAS wrote:
[...]
> $ echo ciao | gawk '{$1=$1}1' FS= OFS=.
> c.i.a.o

An explanation, as requested to me by e-mail:

Setting "FS" to the null string for the GNU awk (it's a GNU
extension) causes gawk to make one field out of each character
in the record.

OFS=.
sets the output field separator to "."

Accessing $1 causes gawk to perform the word splitting ($1="c",
$2="i"... as per "FS"). Assigning something to "$1" causes awk
to rebuild "$0". So, {$1=$1} causes $0 to become "c.i.a.o" ($1
OFS $2 OFS $3 OFS $4).

"1" is a true condition. Default action is to print $0. So "1"
causes awk to print "$0", all of these are equivalent:

1{print $0}
2{print}
{print}
3

The whole could be written:

echo ciao | gawk '
  BEGIN { FS=""; OFS="." }
  { $1=$1; print $0 }'

-- 
St�phane
0
Stephane
10/13/2003 1:21:59 PM
Reply: