![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assigning values to an array via for/while loop | fiori_musicali | Shell Programming and Scripting | 2 | 11-24-2008 11:01 PM |
| Assigning the values to an Array | kkraja | Shell Programming and Scripting | 1 | 08-11-2008 06:28 AM |
| string manipulating | psalas | UNIX for Dummies Questions & Answers | 9 | 04-15-2008 10:00 AM |
| assigning values to a variable | trichyselva | UNIX for Dummies Questions & Answers | 3 | 12-14-2007 01:55 AM |
| Assigning values to an array | yongho | UNIX for Dummies Questions & Answers | 4 | 07-13-2005 08:49 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
retreiving and assigning values and manipulating string in a for loop
Hi
I am new to shell scripting and i am preparing a script. for now i am work on a sub part of it..but i am unable to make it work. --- the test code that i am working on -------------------------- IFS="" Sample_eve=`psg proc_s | grep tY` n=0 for line in $Sample_eve do n=`expr $n + 1` Sam$n=$(`echo $line |awk -F" " {print $5}' |awk -F":" '{print $2}'`) echo $Sam$n done ---------------------------- what i am trying to this is.. list all the process named proc_s that are currently running and are on the machine tY.. populate them in the variable Sample_eve. and then access each line from the Sample_eve and process them on an individual basis. but it is not happening ..for loop only goes through once..if i do not set IFS="" then line takes word by word data from the $Sample_eve...by which i cannot get seperate start time for each process. (it runs 35 times for 4 lines..i want to make it run only 4 time for 4 line). i am doing `echo $line |awk -F" " {print $5}' |awk -F":" '{print $2}'` ..so as to get the start time for each process in minutes..then i am assigning it into array Sam so as to get the start Minute for each process. but getting an output error like this.. for this array assignment as Test[9]: 04^J28^J04^J09: not found. 04, 28,04,09 are correctly shown they are the minutes ..but is not in a proper manner. i am stuck with this thing .. please help me. I am unable to make the code work. i am using the korn shell. thanks |
|
||||
|
Quote:
This will work... Code:
Sam=`echo $line |awk -F" " {print $5}' |awk -F":" '{print $2}'`
|
|
||||
|
Quote:
----------- Hi thanks.. the code you gave worked. but further while accessing the array Sam. i am having some issues. 1: When i echo ${Sam[$2]} rather than giving the 2nd element it prints all of them 2: for (( i = 0 ; i < ${#Sam[@]} ; i++ )) do echo ${Sam[$i]} done its throwing an error Test[16]: syntax error at line 17 : `((' unexpected can you please tell how to go about accessing the array.. |
|
||||
|
Quote:
I am giving an example of Array and for loop for you... Code:
set -A _Array 1 2 3 4 5
for i in ${_Array[@]}
do
echo $i
done
|
|
||||
|
Quote:
Yeah . but what to do if only the second element of the array Sam has to be echoed.. and why does echo ${Sam[$2]} prints the entire Sam array?? |
|
||||
|
Tried..but its not printing anything...any other way u know to do this. the test code is IFS="" eve=`psg ftp | grep tV` n=0 for line in $eve do n=`expr $n + 1` echo $line array=`echo $line |awk -F" " '{print $5}' |awk -F":" '{print $2}'` echo ${array[2]} done |
| Sponsored Links | ||
|
|