ksh - comma seperate input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh - comma seperate input
# 1  
Old 07-06-2006
ksh - comma seperate input

What is a good way to iterate through a variable that has values seperated by a comma?
I thought about converting the commas to spaces, but that sounds inefficent to me. I am using KSH for my shell script. Thank you for any input you can provide.

For example:


Code:
X=55,22,34,61,18
for i in `echo $X | nawk -F , ....`; do
     myfunction $i
done

# 2  
Old 07-06-2006
maybe:
Code:
X=55,22,34,61,18
IFS=,
for i in `echo $X`
     myfunction $i
done
IFS=" "

# 3  
Old 07-06-2006
x=55,22,34,61,18
y=`echo $x|awk -F"," '{print NF}'`

i=1
while [ $i -le $y ]
do
val=`echo $x| cut -d ',' -f$i`
myfunction $val
i=`expr $i + 1`
done
# 4  
Old 07-06-2006
I'd say it depends on how you get the values of x, and how you process those values.
Without knowing how you get those values nor the full scope of what you are trying to accomplish, I'd say, probably you should look into making x an array, rather than just a variable.
# 5  
Old 11-05-2008
Dear team


DATE/TIME,Request,Response,/Air:GetFaFList_3.0:In,/Air:UpdateFaFList_3.0:In,/Air:GetAllowedServiceClasses_3.0:In,/Air:UpdateServiceClass_3.0:In,/Air:GetAccumulators_3.0:In,/Air:GetBalanceAndDate_3.0:In,/Air:UpdateAccountDetails_3.0:In,/Air:UpdateCommunityList_3.0:In,/Air:UpdateAccumulators_3.0:In,/Air:UpdateSubscriberSegmentation_3.0:In,/Air:GetAccountDetails_3.0:In,/Air:UpdateBalanceAndDate_3.0:In,/Air:UpdateTemporaryBlocked_3.0:In,/Air:UpdateRefillBarring_3.0:In,/Air:UpdatePromotionPlan_3.0:In,/Air:GetPromotionPlans_3.0:In,/Air:GetPromotionCounters_3.0:In,/Air:UpdatePromotionCounters_3.0:In,/Air:InstallSubscriber_3.0:In,/Air:LinkSubordinateSubscriber_3.0:In,/AirSmilieeleteSubscriber_3.0:In,/Air:Refill_3.0:In,/Air:GetRefillOptions_3.0:In,/Air:GetFaFList_3.1:In,/Air:UpdateFaFList_3.1:In,/Air:GetAllowedServiceClasses_3.1:In,/Air:UpdateServiceClass_3.1:In,/Air:GetAccumulators_3.1:In,/Air:GetBalanceAndDate_3.1:In,/Air:UpdateAccountDetails_3.1:In,/Air:UpdateCommunityList_3.1:In,/Air:UpdateAccumulators_3.1:In,/Air:UpdateSubscriberSegmentation_3.1:In,/Air:GetAccountDetails_3.1:In,/Air:UpdateBalanceAndDate_3.1:In,/Air:UpdateTemporaryBlocked_3.1:In,/Air:UpdateRefillBarring_3.1:In,/Air:UpdatePromotionPlan_3.1:In,/Air:GetPromotionPlans_3.1:In,/Air:GetPromotionCounters_3.1:In,/Air:UpdatePromotionCounters_3.1:In,/Air:InstallSubscriber_3.1:In,/Air:LinkSubordinateSubscriber_3.1:In,/AirSmilieeleteSubscriber_3.1:In,/Air:Refill_3.1:In,/Air:GetRefillOptions_3.1:In,/Air:ValueVoucherRefillARequest_2.0:In,/Air:StandardVoucherRefillARequest_2.0:In,/Air:RefillARequest_2.0:In,/Air:RefillTRequest_2.0:In,/Air:StandardVoucherRefillTRequest_2.0:In,/Air:ValueVoucherRefillTRequest_2.0:In,/Air:ValueVoucherRefillARequest_2.1:In,/Air:StandardVoucherRefillARequest_2.1:In,/Air:RefillARequest_2.1:In,/Air:RefillTRequest_2.1:In,/Air:StandardVoucherRefillTRequest_2.1:In,/Air:ValueVoucherRefillTRequest_2.1:In,/Air:GetVoucherRefillOptionsTRequest_2.1:In,/Air:ValueVoucherRefillARequest_2.2:In,/Air:StandardVoucherRefillARequest_2.2:In,/Air:RefillARequest_2.2:In,/Air:RefillTRequest_2.2:In,/Air:StandardVoucherRefillTRequest_2.2:In,/Air:ValueVoucherRefillTRequest_2.2:In,/Air:GetVoucherRefillOptionsTRequest_2.2:In,/Air:ValueVoucherRefillARequest_2.3:In,/Air:StandardVoucherRefillARequest_2.3:In,/Air:RefillARequest_2.3:In,/Air:RefillTRequest_2.3:In,/Air:StandardVoucherRefillTRequest_2.3:In,/Air:ValueVoucherRefillTRequest_2.3:In,/Air:GetVoucherRefillOptionsTRequest_2.3:In,/Air:SuperRefillT_2.3:In,/Air:GetAccountDetailsTRequest_2.0:In,/Air:BalanceEnquiryTRequest_2.0:In,/Air:ValueVoucherEnquiryTRequest_2.0:In,/Air:AccumulatorEnquiryTRequest_2.0:In,/Air:UpdateAccountDetailsTRequest_2.0:In,/Air:GetAccountDetailsTRequest_2.1:In,/Air:UpdateAccountDetailsTRequest_2.1:In,/Air:BalanceEnquiryTRequest_2.1:In,/Air:ValueVoucherEnquiryTRequest_2.1:In,/Air:AccumulatorEnquiryTRequest_2.1:In,/Air:GetAccountDetailsTRequest_2.2:In,/Air:UpdateAccountDetailsTRequest_2.2:In,/Air:BalanceEnquiryTRequest_2.2:In,/Air:ValueVoucherEnquiryTRequest_2.2:In,/Air:AccumulatorEnquiryTRequest_2.2:In,/Air:GetAccountDetailsTRequest_2.3:In,/Air:UpdateAccountDetailsTRequest_2.3:In,/Air:BalanceEnquiryTRequest_2.3:In,/Air:ValueVoucherEnquiryTRequest_2.3:In,/Air:AccumulatorEnquiryTRequest_2.3:In,/Air:AdjustmentTRequest_2.0:In,/Air:AdjustmentTRequest_2.1:In,/Air:AdjustmentTRequest_2.2:In,/Air:AdjustmentTRequest_2.3:In,/Air:GetFaFListTRequest_2.1:In,/Air:UpdateFaFListTRequest_2.1:In,/Air:GetFaFListTRequest_2.2:In,/Air:UpdateFaFListTRequest_2.2:In,/Air:GetFaFListTRequest_2.3:In,/Air:UpdateFaFListTRequest_2.3:In,/Air:GetAllowedServiceClassChangesTRequest_2.1:In,/Air:UpdateServiceClassTRequest_2.1:In,/Air:GetAllowedServiceClassChangesTRequest_2.2:In,/Air:UpdateServiceClassTRequest_2.2:In,/Air:GetAllowedServiceClassChangesTRequest_2.3:In,/Air:UpdateServiceClassTRequest_2.3:In
2008-11-04-0000,105,105,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,31,2,65,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0



1: delete the first line that is in english.

2: the MAX of values

105
118
128
145
100

3: average of values


105
118
128
145
100

kindly help me
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh to read input until QUI

Hello all I'm looking to write a simple script (ksh/sh/bsh) to read user input and write it to a file (adding each time) until the user enters QUIT at which point I'm hoping to ask some more questions. Any help much apprecited (2 Replies)
Discussion started by: Grueben
2 Replies

2. Shell Programming and Scripting

ksh loop to read input until QUIT

Hi I'm looking to write a simple ksh loop reading user input (and write it to a file) until the user enters QUIT at which point I want it to continue. Does anyone have an example of this type of loop? Any help much appreciated Cheers (2 Replies)
Discussion started by: Grueben
2 Replies

3. Programming

Date format change from mm/dd/yyyy to yyyymmdd in comma seperate line in perl

Hi All, I have line ,A,FDRM0002,12/21/2017,,0.961751583,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, it contains date in mm/dd/yyyy format i want to change this to yyyymmdd format using perl. Use code tags, thanks. (8 Replies)
Discussion started by: vishal0746
8 Replies

4. Shell Programming and Scripting

Separating list of input files (*.file) with a comma in bash script

Hi all, I'm trying to get a bash script working for a program (bowtie) which takes a list of input files (*.fastq) and assembles them to an output file (outfile.sam). All the .fastq files are in one folder in my home directory (~/infiles). The problem is that the 'bowtie' requires that... (7 Replies)
Discussion started by: TuAd
7 Replies

5. Shell Programming and Scripting

Input Validation of comma separated values

Hello all, I am working on a script and have the first part solved of numerical input validation. Below the code validates that the input is a numerical value between 100 and 1000. If not, it errors out. Now I need to be able to read values separated by a comma. For example, instead of my... (5 Replies)
Discussion started by: LinuxRacr
5 Replies

6. Shell Programming and Scripting

How to run a ksh in bg after passing input

Hello, I've got a KSH which I use to monitor processes then email me when complete. I pass the process name to the script and the update interval. Does anyone know how I can get this to execute in the background. I can't use 'scriptname &' as it starts in the background before reading in my... (3 Replies)
Discussion started by: Grueben
3 Replies

7. Shell Programming and Scripting

KSH: Compare variable to $1 in an input file

Hello, I am working with KSH on AIX and I have 2 files generated from different sources... as seen below: FILE1 FILE2 AAA AAA@ABS0001C BBB BBB@ABS0003D CCC CCC@ABS0023A DDD DDD@ABC0145D EEE EEE@ABS0090A FFF FFF@ABS0002A GGG GGG@ABC0150D HHH FILE1 is main main data source,... (4 Replies)
Discussion started by: right_coaster
4 Replies

8. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies

9. Shell Programming and Scripting

ksh: cmd output to input of another script

I want to write a script in KSH that takes the output of one command and redisplays it. Something like: while true do read inpt date +"%I:%M:%S %p <-> $inpt" done and then some how get the output of the ping command to redirect to the input of this script. does that make sense? (2 Replies)
Discussion started by: IMTheNachoMan
2 Replies

10. Shell Programming and Scripting

Help reading an input file in KSH

First I' d like to say you guys are awesome. :) I have a word document that I cut and paste into Textpad and it removed all the fancy formatting which is fine with me. I WinScp'd it to the box and and called it inputfile.txt. Opened it in vi and don't see any special characters or stuff that... (2 Replies)
Discussion started by: zilla30066
2 Replies
Login or Register to Ask a Question