print Index with each line in awk

Go To StackoverFlow.com

0

For the first time the select display the options and it works fine but when I break from screenTwo function to come into this menu (previuos) it ask me for the selection but does not display the options, how can I handle this?

 PS3="Please make a selection => " ; export PS3
    select var in `awk -F "#" '{print $4}' ${Temp_Config_File} | uniq` PREVIOUS
    do
    echo "\n`date +"%d%m%Y%H%M%S"` Daemon $var selected " >> $Log_File
    if [ -z $var ] ; then echo "\n\tPlease enter a valid choice \n " ; continue
    else  
        if [ $var = "PREVIOUS" ]; then 
            #removeFiles
            break 
        fi
            screenTwo $var

    fi
    done

First Option : Please give me your idea.

Second option : Capture the return of screenTwo and whenever it is break use awk to print the index with $4. (like below , but I dont like it)

if [ $breakStat -eq 99 ]; then
     i=1
     echo "\n\nPlease choose one of the following deamon you wish to Start/Stop\n\n"
     awk -F "#" '{print $4}' Temp_OPDaemon_Config.cfg | uniq | while read line
     do
     echo "${i}) ${line}"
     let i=i+1
     done
     echo "${i}) PREVIOUS"
fi

Thanks

2012-04-04 07:48
by Kimi
If you are just trying to add line numbers to the output, just pipe the output to nl: 'awk ... | uniq | nl - William Pursell 2012-04-04 13:38
this is working , but for the PREVIOUS to display I have to add smthing more - Kimi 2012-04-04 14:46
awk -F "#" '{print $4 }' ${TempConfigFile} | uniq | awk -F "#" '{print NR ") " $0} END {print NR+1") PREVIOUS"} - Kimi 2012-04-04 14:48
{ awk ... | uniq; echo PREVIOUS; } | n - William Pursell 2012-04-05 03:28
StartStop> {awk -F "#" '{print $4 }' TempOPDaemon_Config.cfg | uniq ; echo PREVIOUS;} | nl ksh: syntax error: `}' unexpecte - Kimi 2012-04-05 11:54
You need a space between the ; and the - William Pursell 2012-04-05 12:09


1

this is what I did to handle it .

PS3="Please make a selection => " ; export PS3
select var in `awk -F "#" '{print $4}' ${Temp_Config_File} | uniq` PREVIOUS
do
echo "${Date_Time} Daemon $var selected \n" >> $Log_File
if [ -z $var ] ; then echo "\n\tPlease enter a valid choice \n " ; continue
else  
    if [ $var = "PREVIOUS" ]; then 
        #removeFiles
        break 
    fi
    while : 
    do
        screenTwo $var
        breakStat=$?
        if [ $breakStat -eq 99 ]; then
         break
         elif [ $breakStat -eq 98 ]; then
         continue
        fi
    done

if [ $breakStat -eq 99 ]; then
    echo "\n\nPlease choose one of the following deamon you wish to Start/Stop\n\n"
    awk -F "#" '{print $4 }' ${Temp_Config_File} | uniq | awk -F "#" '{print NR ") " $0} END {print NR+1") PREVIOUS"}'
fi


fi
done
2012-04-05 07:06
by Kimi
Ads