Need your help to get the output of the list in desired format

Hello Guys,

I am working on a script and using the below code to fetch the list of all repositories
CHDIR='/mnt/scm/subversion/'

repolist()
{
cd ${CHDIR}
Repo=`ls|cut -d " " -f1`
echo $Repo
}

Output of the above code is

BSB CIB COB DCI DIB DSB ESB-P ESB-TOOLS FareVerify GCACHE GWY IBMSOAMB IBMSOAWAS ISM KESTREL-DEV kestrel-migration KESTREL-UAPI KESTREL-XD LAMB LinuxAutomation MGLNO PORTAL repos4 SCMTools SESTOKEN SMB SOA SPLASH SSB STP TOI

Diretory from where I am fetching the list
[e030809@vhldvspusv011 ~]$ cd /mnt/scm/subversion/
[e030809@vhldvspusv011 subversion]$ pwd
/mnt/scm/subversion
[e030809@vhldvspuv011 subversion]$ ll -tr
total 124
drwxr-xr-x 7 apache apache 4096 May 21 2009 COB
drwxr-xr-x 7 apache apache 4096 May 26 2009 CIB
drwxr-xr-x 7 apache apache 4096 May 26 2009 DIB
drwxr-xr-x 7 apache apache 4096 Jun 24 2009 GCACHE
drwxr-xr-x 7 apache apache 4096 Jun 24 2009 LAMB
drwxr-xr-x 7 apache apache 4096 Jul 28 2009 ISM
drwxr-xr-x 7 apache apache 4096 Jul 28 2009 repos4
drwxr-xr-x 7 apache apache 4096 Jul 29 2009 ESB-P
drwxrwxr-x 7 apache apache 4096 Aug 19 2009 KESTREL-DEV
drwxrwxr-x 7 apache apache 4096 Aug 19 2009 KESTREL-UAPI
drwxrwxr-x 7 apache apache 4096 Sep 21 2009 KESTREL-XD
drwxrwxr-x 7 apache apache 4096 Oct 9 2009 SMB
drwxrwxr-x 7 apache apache 4096 Nov 19 2009 PORTAL
drwxrwxr-x 7 apache apache 4096 Jan 12 2010 MGLNO
drwxrwxr-x 7 apache apache 4096 Jan 21 2010 BSB
drwxrwxr-x 7 apache apache 4096 Jan 26 2010 SSB
drwxrwxr-x 7 apache apache 4096 Feb 18 2010 SPLASH
drwxrwxr-x 7 apache apache 4096 Apr 13 2010 ESB-TOOLS
drwxrwxr-x 6 apache apache 4096 Apr 23 2010 SOA
drwxrwxr-x 7 apache apache 4096 May 26 2010 SCMTools
drwxrwxr-x 7 apache apache 4096 Jun 15 2010 SESTOKEN
drwxrwxr-x 7 apache apache 4096 Nov 10 2010 LinuxAutomation
drwxrwxr-x 7 apache apache 4096 Dec 20 2010 TOI
drwxrwxr-x 7 apache apache 4096 Jan 21 2011 STP
drwxrwxr-x 7 apache apache 4096 Mar 11 20:59 IBMSOAMB
drwxrwxr-x 7 apache apache 4096 Mar 11 21:05 IBMSOAWAS
drwxrwxr-x 7 apache apache 4096 Mar 25 19:33 DCI
drwxrwxr-x 7 apache apache 4096 Apr 29 20:13 DSB
drwxrwxr-x 7 apache apache 4096 May 9 21:37 FareVerify
drwxrwxr-x 2 root kestrel_dev_appsupport 4096 Jun 29 18:10 kestrel-migration
drwxrwxr-x 7 apache apache 4096 Jul 21 20:50 GWY

Now my question is how I make this list in the format or output

1.BSB 2.CIB 3.COB 4.DCI 5.DIB 6.DSB 7.ESB-P 8.ESB-TOOLS 9.FareVerify 10.GCACHE 11.GWY 12. IBMSOAMB 13.IBMSOAWAS 14.ISM 15.KESTREL-DEV 16.kestrel-migration 17.KESTREL-UAPI 18.KESTREL-XD 19.LAMB 20.LinuxAutomation 21.MGLNO 22.PORTAL 23.repos4 24.SCMTools 25.SESTOKEN 26.SMB 27.SOA 28.SPLASH 29.SSB 30.STP 31.TOI

and also If I want to check the codebase of the above repository I want to select it with numbering options like 1 to 31(1....31 the number of repositry)

Thanks in advance
Rohit Sing

Try this.. not tested

 
repolist()
{
 cd ${CHDIR}
 Repo=`ls|cut -d " " -f1`
 count=0
 echo "$Repo" | while read line; do count=`echo $count + 1 | bc`; echo -n " $count : $line "; done
}

thanks this code is working fine for me but my script 2nd option "Check for Repository latest codebase" need repository name but I don't want this I want the user just only enter the option like 1 to 31(1....31) neither name of the repositiry.Please suggest.

1)BSB 2)CIB 3)COB 4)DCI 5)DIB 6)DSB 7)ESB-P 8)ESB-TOOLS 9)FareVerify 10)GCACHE 11)GWY 12)IBMSOAMB 13)IBMSOAWAS 14)ISM 15)KESTREL-DEV 16)kestrel-migration 17)KESTREL-UAPI 18)KESTREL-XD 19)LAMB 20)LinuxAutomation 21)MGLNO 22)PORTAL 23)repos4 24)SCMTools 25)SESTOKEN 26)SMB 27)SOA 28)SPLASH 29)SSB 30)STP 31)TOI

      Enter options from 1 to 4


      1 Check for Repository list

      2 Check for Repository latest codebase

      3 Check for Repository User's list for contributors and users

      4 Exit

           Select Menu Number [ 1 - 4 ]:

Press 2 and

Enter the repository name :

i dont understand your request

My request is let suppose if you have a script.I run that script and it gives the below prompt then I want to enter the repo. number not repo. name that I get from above code.

1.BSB 2.CIB 3.COB 4.DCI 5.DIB 6.DSB 7.ESB-P 8.ESB-TOOLS 9.FareVerify 10.GCACHE 11.GWY 12. IBMSOAMB 13.IBMSOAWAS 14.ISM 15.KESTREL-DEV 16.kestrel-migration 17.KESTREL-UAPI 18.KESTREL-XD 19.LAMB 20.LinuxAutomation 21.MGLNO 22.PORTAL 23.repos4 24.SCMTools 25.SESTOKEN 26.SMB 27.SOA 28.SPLASH 29.SSB 30.STP 31.TOI

Enter the repository name :28(for example)I don't want to use repo. name here

something like this ?

 
repolist()
{
 cd ${CHDIR}
 Repo=`ls|cut -d " " -f1`
 echo "Enter the REPO # : "
 read usrInput
 count=0
 echo "$Repo" | while read line; do count=`echo $count + 1 | bc`; echo " $count : $line "; done | grep $usrInput 
}

getting the below output.i need to restrict it to a single value . as in grep when i give 3 it will search for 3, 13, 23 etc (where 3 appears) . i need it to display only a single value corresponding to that number.

BSB
CIB
COB
DCI
DIB
DSB
ESB-P
ESB-TOOLS
FareVerify
GCACHE
GWY
IBMSOAMB
IBMSOAWAS
ISM
KESTREL-DEV
kestrel-migration
KESTREL-UAPI
KESTREL-XD
LAMB
LinuxAutomation
MGLNO
PORTAL
repos4
SCMTools
SESTOKEN
SMB
SOA
SPLASH
SSB
STP
TOI
Enter the REPO # :
3
3 : COB
13 : IBMSOAWAS
23 : repos4
30 : STP
31 : TOI

use

grep -w

Now I am getting the desired result for my script
I used one more thing head -1

repolist() { cd ${CHDIR} Repo=`ls|cut -d " " -f1` echo "Enter the REPO # : " read usrInput count=0 echo "$Repo" | while read line; do count=`echo $count + 1 | bc`; echo " $count : $line "; done | grep $usrInput|head -1 }

output
1)BSB 2)CIB 3)COB 4)DCI 5)DIB 6)DSB 7)ESB-P 8)ESB-TOOLS 9)FareVerify 10)GCACHE 11)GWY 12)IBMSOAMB 13)IBMSOAWAS 14)ISM 15)KESTREL-DEV 16)kestrel-migration 17)KESTREL-UAPI 18)KESTREL-XD 19)LAMB 20)LinuxAutomation 21)MGLNO 22)PORTAL 23)repos4 24)SCMTools 25)SESTOKEN 26)SMB 27)SOA 28)SPLASH 29)SSB 30)STP 31)TOI

Enter the REPO number(1,2...):23
23)repos4

Can u help me to cut the above output
right now it's showing me
23)repos4 but I want this in repos4 only

Thanks in advance

---------- Post updated at 06:52 PM ---------- Previous update was at 06:20 PM ----------

Now I have also got the desired output through cut commnand

Thank you very much for your kind help
Rohit

---------- Post updated at 11:24 PM ---------- Previous update was at 06:52 PM ----------

Hello Guys,

The output of my file is below and I want to delete those lines from the file where these kind of numbers (e.g. 11.2.13.1)are coming.Highlighted in red

BSB/
BSB/ADS
CIB/
CIB/CRH
CIB/DCC
CIB/EMD
CIB/GDSPresentation
CIB/HCH
CIB/HSM
CIB/MCH
CIB/RCH
COB/
DCI/
DIB/
DIB/H2H
DIB/HotelSync
DIB/UADBA
DSB/
DSB/HotelETL
ESB-P/
ESB-TOOLS/
FareVerify/
GCACHE/
GWY/
IBMSOAMB/
IBMSOAWAS/
ISM/
KESTREL-DEV/
KESTREL-UAPI/
KESTREL-UAPI/branches/11.0
KESTREL-UAPI/branches/11.1
KESTREL-UAPI/branches/11.1.09.2
KESTREL-UAPI/branches/11.2
KESTREL-UAPI/branches/11.2.13.1
KESTREL-UAPI/branches/11.3
KESTREL-XD/
LAMB/
LinuxAutomation/
MGLNO/
PORTAL/
PORTAL/AdminPortal
PORTAL/Common
PORTAL/TUD
PORTAL/UDP
PORTAL/UDP/udportal/branches/11.00.04
PORTAL/UDP/udportal/trunk
repos4/
SCMTools/
SESTOKEN/
SMB/
SOA/
SPLASH/branches
SPLASH/tags
SSB/SystemServices
STP/
TOI/

Thanks in advance

 
grep -v "[0-9]" fileName

Below is the code but I need one more thing here.This code works fine and list the repo with numbers.I need here is

I want to restrict the person to enter 0(zero) as well as to enter exceed than count .i.e. if count=56 and if he enters 57 it should not work and same for 0 because here
what happens when I enter 0 it say no repo. exist but it pick the value of those repo. which contains 0 (for. eg. KESTREL-UAPI/branches/11.0).and same for max. count(for e.g. if KESTREL-UAPI/branches/11.57) then it should also not work.

repocodebase()
{
echo -en "Enter the REPO number(1,2...):"
read usrInput
count=0
cat /home/e030809/temp.txt2|while read line; do count=`echo $count + 1 | bc`; echo " $count)$line "; done | grep -w $usrInput>/home/e030809/temp.txt3
}

List of repo:-

1)BSB
2)BSB/ADS
3)CIB
4)CIB/CRH
5)CIB/DCC
6)CIB/EMD
7)CIB/GDSPresentation
8)CIB/HCH
9)CIB/HSM
10)CIB/MCH
11)CIB/RCH
12)COB
13)DCI
14)DIB
15)DIB/H2H
16)DIB/HotelSync
17)DIB/UADBA
18)DSB
19)DSB/HotelETL
20)ESB-P
21)ESB-TOOLS
22)FareVerify
23)GCACHE
24)GWY
25)IBMSOAMB
26)IBMSOAWAS
27)ISM
28)KESTREL-DEV
29)KESTREL-UAPI
30)KESTREL-UAPI/branches/11.0
31)KESTREL-UAPI/branches/11.1
32)KESTREL-UAPI/branches/11.1.09.2
33)KESTREL-UAPI/branches/11.2
34)KESTREL-UAPI/branches/11.2.13.1
35)KESTREL-UAPI/branches/11.3
36)KESTREL-XD
37)LAMB
38)LinuxAutomation
39)MGLNO
40)PORTAL
41)PORTAL/AdminPortal
42)PORTAL/Common
43)PORTAL/TUD
44)PORTAL/UDP
45)PORTAL/UDP/udportal/branches/11.00.04
46)PORTAL/UDP/udportal/trunk
47)repos4
48)SCMTools
49)SESTOKEN
50)SMB
51)SOA
52)SPLASH/branches
53)SPLASH/tags
54)SSB/SystemServices
55)STP
56)TOI

Thanks-
Rohit Singh

 
repocodebase()
{
echo -en "Enter the REPO number(1,2...):"
read usrInput
count=0
fileName="/home/e030809/temp.txt2"
while read line; do count=`echo $count + 1 | bc`; echo " $count)$line "; done < $fileName
[ "$usrInput" -le "$count" -o "$usrInput" -ne "0" ] && grep -w $usrInput > /home/e030809/temp.txt3 || echo "No Repo Exists"
}

Example to use select. Ksh93 and bash support it. Like for except give the selection prompt.

cd $CHDIR
PS3="Your choice (ENTER=menu again, e=end):"
select f in *
do
        [ "$REPLY" = "e" ] && break
        echo "Choice: ($REPLY) $f"
        [ ! -f "$f" ] && echo "not regular file" >&2 && continue
        echo $f
        # if like to exit after 1st selection, then add line break
        # break
done

I tried your code but I don't why it's not working when I enter 0 it doesn't give me
"No Repo Exists" either I enter more than the count.I aslo checked the temp.txt3 this file is also empty on entering the valid number.When I enter the repo number after that it is also displaying the whole list that is not required.I also echo the value of userinput and count and its giving me the correct response.Please do the needful
#!/bin/bash

repocodebase()
{
echo -en "Enter the REPO number(1,2...):"
read usrInput
count=0
fileName="/home/e030809/temp.txt2"
while read line; do count=`echo $count + 1 | bc`; echo " $count)$line "; done < "$fileName"
echo $usrInput
echo $count
[ "$usrInput" -le "$count" -o "$usrInput" -ne "0" ] && grep -w $usrInput > /home/e030809/temp.txt3 || echo "No Repo Exists"
}
repocodebase

output

[e030809@vhldvsmsv001 ~]$ ./test
Enter the REPO number(1,2...):0
1)BSB
2)BSB/ADS
3)CIB
4)CIB/CRH
5)CIB/DCC
6)CIB/EMD
7)CIB/GDSPresentation
8)CIB/HCH
9)CIB/HSM
10)CIB/MCH
11)CIB/RCH
12)COB
13)DCI
14)DIB
15)DIB/H2H
16)DIB/HotelSync
17)DIB/UADBA
18)DSB
19)DSB/HotelETL
20)ESB-P
21)ESB-TOOLS
22)FareVerify
23)GCACHE
24)GWY
25)IBMSOAMB
26)IBMSOAWAS
27)ISM
28)KESTREL-DEV
29)KESTREL-UAPI
30)KESTREL-UAPI/branches/11.0
31)KESTREL-UAPI/branches/11.1
32)KESTREL-UAPI/branches/11.1.09.2
33)KESTREL-UAPI/branches/11.2
34)KESTREL-UAPI/branches/11.2.13.1
35)KESTREL-UAPI/branches/11.3
36)KESTREL-XD
37)LAMB
38)LinuxAutomation
39)MGLNO
40)PORTAL
41)PORTAL/AdminPortal
42)PORTAL/Common
43)PORTAL/TUD
44)PORTAL/UDP
45)PORTAL/UDP/udportal/branches/11.00.04
46)PORTAL/UDP/udportal/trunk
47)repos4
48)SCMTools
49)SESTOKEN
50)SMB
51)SOA
52)SPLASH/branches
53)SPLASH/tags
54)SSB/SystemServices
55)STP
56)TOI
0
56

Thanks-
Rohit Singh

 
replace -o with -a

Its working but again there is one problem

while I am giving the right output it's not store any thing in file temp.txt3

code in my file is
#!/bin/bash

repocodebase()
{
echo -en "Enter the REPO number(1,2...):"
read usrInput
count=0
fileName="/home/e030809/temp.txt2"
while read line; do count=`echo $count + 1 | bc`; echo " $count)$line "; done < "$fileName"
echo $usrInput
echo $count
[ "$usrInput" -le "$count" -a "$usrInput" -ne "0" ]&& grep -w $usrInput > /home/e030809/temp.txt3 || echo "No Repo Exists"
}
repocodebase

format of temp.txt2
BSB
BSB/ADS
CIB
CIB/CRH
CIB/DCC
CIB/EMD
CIB/GDSPresentation
CIB/HCH
CIB/HSM
CIB/MCH
CIB/RCH
COB
DCI
DIB
DIB/H2H
DIB/HotelSync
DIB/UADBA
DSB
DSB/HotelETL
ESB-P
ESB-TOOLS
FareVerify
GCACHE
GWY
IBMSOAMB
IBMSOAWAS
ISM
KESTREL-DEV
KESTREL-UAPI
KESTREL-UAPI/branches/11.0
KESTREL-UAPI/branches/11.1
KESTREL-UAPI/branches/11.1.09.2
KESTREL-UAPI/branches/11.2
KESTREL-UAPI/branches/11.2.13.1
KESTREL-UAPI/branches/11.3
KESTREL-XD
LAMB
LinuxAutomation
MGLNO
PORTAL
PORTAL/AdminPortal
PORTAL/Common
PORTAL/TUD
PORTAL/UDP
PORTAL/UDP/udportal/branches/11.00.04
PORTAL/UDP/udportal/trunk
repos4
SCMTools
SESTOKEN
SMB
SOA
SPLASH/branches
SPLASH/tags
SSB/SystemServices
STP
TOI