Need help in loop script

Hi,

This is script i am using currently for create SAN device creating. I need to do some change on this script

#!/bin/ksh
let x=0
let y=0
let count=$1
let size=$2
for dev in `cat /opt/emc/scripts/bin/noport-devs`
do
        if [[ "$dev" > "$start" ]]
        then
        if [ y -eq $count ]
        then
                exit
        fi
        if [ x -eq 0 ]
        then
                head=$dev 
                echo "form meta from dev $dev config=striped stripe_size=1920;"
        else
                echo "add dev $dev to meta $head;"
                
        fi
        let x=x+1
        if [ x -eq $size ]
        then
                let x=0
                let y=y+1
        fi
        fi

done

Curent output for the above script is

orm meta from dev 05DF config=striped stripe_size=1920;
add dev 05E1 to meta 05DF;
add dev 0657 to meta 05DF;
add dev 066C to meta 05DF;
form meta from dev 066D config=striped stripe_size=1920;
add dev 09F2 to meta 066D;
add dev 09F3 to meta 066D;
add dev 09F4 to meta 066D;
form meta from dev 09F5 config=striped stripe_size=1920;
add dev 09F6 to meta 09F5;
add dev 09F7 to meta 09F5;
add dev 09F8 to meta 09F5;

I need the oupput to append with this echo

echo "map dev $head to dir 0:0 LUN=00;"
echo "map dev $head to dir 0:0 LUN=00;"

form meta from dev 05DF config=striped stripe_size=1920;
add dev 05E1 to meta 05DF;
add dev 0657 to meta 05DF;
add dev 066C to meta 05DF;
map dev 05DF to dir 0:0 LUN=00;
map dev 05DF to dir 0:0 LUN=00;
form meta from dev 066D config=striped stripe_size=1920;
add dev 09F2 to meta 066D;
add dev 09F3 to meta 066D;
add dev 09F4 to meta 066D;
map dev 066D to dir 0:0 LUN=00;
map dev 066D to dir 0:0 LUN=00;
form meta from dev 09F5 config=striped stripe_size=1920;
add dev 09F6 to meta 09F5;
add dev 09F7 to meta 09F5;
add dev 09F8 to meta 09F5;
map dev 09F5 to dir 0:0 LUN=00;
map dev 09F5 to dir 0:0 LUN=00;

How i can make this work on the above script

Something like this?

awk -v dev="map dev " $head " to dir 0:0 LUN=00;" '
NR-1 && /^form meta/{print dev; print dev}
END{print dev; print dev}
1' file

Where i need to add this code just on the loop

Sorry, the command shouldn't work, maybe it should be helpful to post the file "/opt/emc/scripts/bin/noport-devs".

Possibly something like this:

#!/bin/ksh
let x=0
let y=0
let count=$1
let size=$2
first=1
for dev in `cat /opt/emc/scripts/bin/noport-devs`
do
        if [[ "$dev" > "$start" ]]
        then
        if [ y -eq $count ]
        then
                exit
        fi
        if [ x -eq 0 ]
        then
                if [ $first -eq 0 ]
                then
                        echo "map dev $head to dir 0:0 LUN=00;"
                        echo "map dev $head to dir 0:0 LUN=00;"
                fi
                head=$dev
                echo "form meta from dev $dev config=striped stripe_size=1920;"
                first=0
        else
                echo "add dev $dev to meta $head;"

        fi
        let x=x+1
        if [ x -eq $size ]
        then
                let x=0
                let y=y+1
        fi
        fi

done
if [ $first -eq 0 ]
then
        echo "map dev $head to dir 0:0 LUN=00;"
        echo "map dev $head to dir 0:0 LUN=00;"
fi

The update script is appeding great. But for the last one it is not updating. What may be issue

---------- Post updated at 09:56 AM ---------- Previous update was at 09:10 AM ----------

Is it possible to delete the lines till the device used? Because now I manually deleting the created device from the /opt/emc/scripts/bin/noport-devs.

In the above example I need to delete the lines till the device ID is "0A30"

I need to delete the lines using sed '1d' /opt/emc/scripts/bin/noport-devs. But dont know how to add in the loop

Sorry, you need to replace the "exit" by "break":

   if [ y -eq $count ]
   then
      break
   fi

Thanks now it is working fine.

Just to know can I make this script to work like this.

I need to create multiple Meta with different combination like 3 4,8 1,2 4 buy using the same file. Any help on this

Output for this above script is

Now need to create multiple Meta with different combination like 3 4,8 1,2 4 buy using the same file. Any help on this [RIGHT] [/RIGHT]