D
D
Dmitry Kuzmin2015-06-09 15:49:18
Perl
Dmitry Kuzmin, 2015-06-09 15:49:18

How to insert the value of a variable in the shell after a certain number of commas?

There are text files where the separators are commas, for example:
18,1445805860,3900,96100,20150523215740,20150523215745,5,16,17,12034543,24066520,DSFG,915,3549,1,2
I need to insert a random value that contains a variable after the 9th comma.
So that in the end there was something:
18,1445805860,3900,96100,20150523215740,20150523215745,5,16,17, 123456 12034543,24066520,DSFG,915,3549,1,2
Random values ​​received: awk -vmin =5 -vmax=10 'BEGIN{srand(); print int(min+rand()*(max-min+1))}'
How best to insert them I can't figure out how to build a construction in SED.
You can also use other editors or perl.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eddy_Em, 2015-06-09
@Dimkaa

echo "1,2,3,4,5,6,7,8,9,10" | sed "s/\(\([^,]\+,\)\{9\}\)/\1$RANDOM/"
1,2,3,4,5,6,7,8,9,629410

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question