Hi All
Been trying to get something working but having some trouble in unix bash or ksh scripting.
Im trying to increment once a condition has been met
Say I have a file that contains:
Code:
apple
orange
banana
grapes
dates
kiwi
What im after is once a counter has reached every second fruit it will increment and display the fruit type.
So what im looking for is a script that outputs like so
Code:
"fruit type is apple in basket1"
"fruit type is orange in basket1"
"fruit type is banana in basket2"
"fruit type is grapes in basket2"
"fruit type is dates in basket3"
"fruit type is kiwi in basket3"
I can get the counter incrementing but having difficulty getting it to do so after the second fruit. This is what i have at the moment:
Code:
#!/bin/bash
i=0
while read a
do
i=`expr $i + 1`
echo "fruit type is $a in basket$i"
done < /tmp/fruit
Output i get at the moment is:
fruit type is apple in basket1
fruit type is orange in basket2
fruit type is banana in basket3
fruit type is grapes in basket4
fruit type is dates in basket5
fruit type is kiwi in basket6
Anyone please able to help?
Thanks
Moderator's Comments:
Please use CODE tags when displaying sample input, output, and code segments.
Last edited by Don Cragun; 02-05-2015 at 08:37 PM..
Reason: Add CODE tags.
Hi All
I need help
am having a source file as below
emp
dept
class
subclass
region
country
division
first i need to get line count and i need to divide by 3 it is an parameter passing value
number of lines 7 (8 Replies)
Hello,
Here's a file of mine:
key1:431
key2:159
key3:998
I need to change these keys to something bigger - and I actually need to shift them all by a range of 3.
The output would be:
key1:434
key2:162
key3:1001
I can't find the propper sed/awk line that would alter all my... (4 Replies)
All:
Benjamin Fournier wrote a plug-in for the graphics application PhotoFiltre Studio that inspired me, since I also happen to use the XnView Shell Extension and have seen what it can do, to look into the possibility of getting Windows XP Pro SP3's Explorer file navigator to "hazard a guess at"... (1 Reply)
Hi Admin, i just noticed that when I do postings, the number does not increment. eg :
Post A -Total Posts 312
Post B - Total Posts 312
Post C - Total Posts 313
Post D - Total Posts 313
Why is this so? Can you kindly check this out? Thank you. (5 Replies)
Folks;
I just installed Apache2.2.6 on Solaris 10 & when i try to start it, i got this message in the error.log file:
Init: Session Cache is not configured
Any help?
Thanks in advance (2 Replies)
I am a student. And need help on following program. I want to make a c program.
I have to scan a sentence and I have to interchange a word from that sentence.
Example: Scan the sentence is " Drilling machine and Milling machine " . Replace the word "machine" by "operation". And output should... (2 Replies)
I have,
LIST="a b c d e"
for word in $LIST
do
echo $word
done
would give me
a
b
c
d
e
With the first iteration of the for loop, I get "a" as the result.
Is it possible that I get both "a" and "b" in only the first iteration.
In the next iteration I get "c" and "d" and so on.... (2 Replies)