Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add , to variable

Status
Not open for further replies.

Marcel1958

Technical User
Oct 11, 2001
38
NL
I have the variable $TRY.

When i print this variable the result is:

1242

Now i will add an , between 124 an the last 2

How can i add this so the result will be

124,2
 
assuming your counter '2' is another variable ${counter}

echo "${TRY},${counter}"

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I see what you mean NOW.
What shell are you using?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Korne shell.

It is the result of:

TRY=$TOTAL01/$COUNT01

In $TOTAL01 and $COUNT01 i removed the , with
tr -d &quot;,&quot;
 
here's the sed way

echo &quot;${TRY}&quot; | sed -e 's:\(.*\)\(.\):\1,\2:'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks Vlad for the support.

Can you tell me the function of the given command. Man sed don't tell me the exact working of the parameters you gave.

Marcel
 
sed -e 's:\(.*\)\(.\):\1,\2:'

\(.*\)\ - capture all the chars from the beginning in capture '1'

(.\) - capture the trailing char in capture '2'

\1,\2 - ouput capture '1' followed by a ',' followed by capture '2'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top