Computing.Net > Forums > Unix > delimiter variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

delimiter variables

Reply to Message Icon

Name: abhargav
Date: May 15, 2005 at 08:05:41 Pacific
OS: unix
CPU/Ram: 256 SDRAM
Comment:

hi
i hav a question,suppose i hav a variable like
var="12,134,13"
now i want to put 12 134 and 13 in a seperate variable.i want to ask how to i replace delimiter and then put these nos in a seperate variable.
like var containing of 12 134 and 13
then i can iterate using for loop

for i in $ var
echo $i

Regards
Abhishek


hi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messages

Mar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:

no



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 15, 2005 at 11:03:53 Pacific
Reply:

Hi:

The easiest way is to change the internal field separater, IFS, and use the set command to do the parsing:


var="12,134,13"
set - $(IFS=","; echo $var)
echo $1
echo $2
echo $3

If you insist on using a loop, this works:

#!/bin/ksh

var="12,134,13"
OFS=$IFS
IFS=","
for i in $var
do
echo "i is: $i"
done
IFS=$OFS # restore original IFS



0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: delimiter variables

two variable input from the same fi www.computing.net/answers/unix/two-variable-input-from-the-same-fi/4970.html

AWK(reading from a variable) www.computing.net/answers/unix/awkreading-from-a-variable/7113.html

Variables in Shell SCripting www.computing.net/answers/unix/variables-in-shell-scripting/6020.html