Text Convert

Hello,

I have a text file(utf8-bom). I want convert to following format. Thank you.

1***hello 35345
29***hello test6
380***bill33
4327***hello test6
47829***hull55
65644***hello test6

I want this format.

1***hello 35345
29***hello test6
380***bill33
4327***hello test6 2
47829***hull55
65644***hello test6 3

Try:

awk -F'[*]{3}' 'A[$2]++{$0=$0 OFS A[$2]}1' infile

Hello,

Thanks but output:

1***hello 35345
29***hello test6
 2
380***bill33
 3
4327***hello test6
 4
47829***hull55
 5
65644***hello test6 6

Could you post this output?

od -c infile

What OS/version are you working on?

Hello,

OS: Centos 5.8
I want add a number only "same words" not all words.

Output:

0000000   1   *   *   *   h   e   l   l   o       3   5   3   4   5  \n
0000020   2   9   *   *   *   h   e   l   l   o       t   e   s   t   6
0000040  \n   3   8   0   *   *   *   b   i   l   l   3   3  \n   4   3
0000060   2   7   *   *   *   h   e   l   l   o       t   e   s   t   6
0000100  \n   4   7   8   2   9   *   *   *   h   u   l   l   5   5  \n
0000120   6   5   6   4   4   *   *   *   h   e   l   l   o       t   e
0000140   s   t   6
0000143

Try:

awk --posix -F'[*]{3}' 'A[$2]++{$0=$0 OFS A[$2]}1' infile

I still don't get how the counter ended up on the next line, could that be due to the way it was cut-and-pasted?

Thanks its works :slight_smile:

I dont know I think this text file needed dos2unix.

Alternatively use:

awk -F'[*]*' 'A[$2]++{$0=$0 OFS A[$2]}1' infile

Great thanks .