I have text file and it has content like this,
40 number of cpu
50 number of errors
and I need to insert comma between number and words. Its should be like this,
40, number of cpu
50, number of errors
I’m really new to linux and I tried some sed and awk commands, but was uneble to found solution.
>Solution :
Put comma after the first word in a line:
sed -E 's/^[[:space:]]*[^[:space:]]+/&,/' file.txt
Put comma after the first word in a line, only if it’s numeric:
sed -E 's/(^[[:space:]]*[0-9]+)([[:space:]]|$)/\1,\2/' file.txt
Put comma after every numeric field:
sed -E 's/(^|[[:space:]])([[:digit:]]+)($|[[:space:]])/\1\2,\3/g' file.txt