Help cannot concatenate Ksh variables ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help cannot concatenate Ksh variables ?
# 22  
Old 02-22-2012
Your echoing set values for your variables.
If you don't want to display OldRep and NewRepo if empty, you need to program for that.
# 23  
Old 02-22-2012
Quote:
for i in `cat ${wcfiles}`
Your main problem is this line. A "for" statement is unsuitable for open-ended lists and totally unsuitable for a list of filenames containing space characters (like yours). What happens is each space-separated piece of the filename gets treated as a separate field.


Replace with a "while" loop:
Code:
cat "${wcfiles}" | while read i
do

Not checked the rest of the script.
# 24  
Old 02-22-2012
Output using while loop:
Code:
snip...
cd AgncyInfoInProc/SalesApplication/Source/bc
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/SWAT https://svnprod.nwie.net/svn/SWAT
cd AgncyInfoInProc/SalesApplication/Source/Distrib
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/SWAT https://svnprod.nwie.net/svn/SWAT
cd AgncyInfoInProc/SalesApplication/Source/Distrib/Release
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/SWAT cd ALPS_ATTACHMENT/Utility EXE Attachment
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/DotNET
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/bin
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/My Project
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/obj
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/obj/Debug
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/obj/Debug/TempPE
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/obj/Release
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/obj/Release/TempPE
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/Release
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/VB6
svn relocate  cd ALPS_ATTACHMENT/Utility EXE Attachment/VB6/Release
svn relocate  https://svnprod.nwie.net/svn/ALPS
cd ALPS_ATTACHMENT/VB6
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS https://svnprod.nwie.net/svn/ALPS
cd ALPS_ATTACHMENT/VB6/Release
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS cd ALPS_CACHE/Athena COM Trackers
svn relocate  cd ALPS_CACHE/COM Cache
svn relocate  cd ALPS_CACHE/COM Cache/Release
svn relocate  https://svnprod.nwie.net/svn/ALPS
cd ALPS_CACHE/MSI
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS cd ALPS_COM/Athena COM Trackers
svn relocate  cd ALPS_COM/COM Attachment
svn relocate  cd ALPS_COM/COM Business Layer
svn relocate  cd ALPS_COM/COM Data Layer
svn relocate  cd ALPS_COM/COM Data Layer/Release
svn relocate  cd ALPS_COM/COM Utilities
svn relocate  cd ALPS_COM/MSI
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/DotNET
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/DotNET/bin
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/DotNET/My Project
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/DotNET/obj
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/DotNET/obj/Debug
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/DotNET/obj/Debug/TempPE
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/DotNET/obj/Release
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/DotNET/obj/Release/TempPE
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/Release
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/VB6
svn relocate  cd ALPS_COMMUNICATIONS/Utility EXE Communication/VB6/Release
svn relocate  https://svnprod.nwie.net/svn/ALPS
cd ALPS_COMMUNICATIONS/VB6
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS https://svnprod.nwie.net/svn/ALPS
cd ALPS_COMMUNICATIONS/VB6/Release
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS https://svnprod.nwie.net/svn/ALPS
snip ...

---------- Post updated at 03:08 PM ---------- Previous update was at 02:26 PM ----------

not that it matters but here is the code that creates the input file
Code:
cd ${bldDirLoc}
find . -type d -exec sh -c '[ -d "$1"/.svn ] || exit 1' sh {} \; -print | cat > ${OutputLoc}/dnaRelwc.txt
`cat ${OutputLoc}/dnaRelwc.txt` | sort -u | sed '$!N; /^\(.*\)\n\1$/!P; D' | sed 's/^.\{2\}//g' | cat > ${OutputLoc}/dnaRelwc1.dat

# 25  
Old 02-22-2012
Not knowing how you changed your loop. (Using original code provided)
I think this is what you want but this whole script is not very efficient..

Code:
for i in `cat ${wcfiles}`
do
    OldRepo=`grep svn01g.gdc ${i}/.svn/entries | tail -1 | tr -d '\n'`
    NewRepo=`grep svn01g.gdc ${i}/.svn/entries | tail -1 | sed '/svn01g.gdc/ s/svn01g.gdc/svnprod/g' | sed 's/\/svn01p//g' | sed 's/\/Repositories//g'`
    
  if [[ $OldRepo -ne "" ]]
  then
      echo "cd" $i
      echo -e "${svnRelcmd}  ${OldRepo}  ${NewRepo}\c"
   fi

done

# 26  
Old 02-22-2012
the while loop that replaced the for loop:
Code:
cat "${wcfiles}" | while read i
do

I agree I am not a programmer. Only started ksh scripts a few years back and not too often.
My goal was to quickly build a script to run svn relocate in over 5000 working copy locations, without manually editing the file. I am almost needing to do just that anyway at this rate.

But I do appreciate the help I am learning as we go.

---------- Post updated at 03:56 PM ---------- Previous update was at 03:44 PM ----------

adding your if statement results in a list of NewRepo only
# 27  
Old 02-22-2012
I guess I don't understand what you are expecting in your output.
Let's step back and try to determine what you are expecting in your output.

Your sample output...
Code:
.
.
svn relocate  cd ALPS_COM/COM Data Layer/Release
svn relocate  cd ALPS_COM/COM Utilities
svn relocate  cd ALPS_COM/MSI
.
.

When OldRepo is null or NewRepo is null, what do you want to display?
Other than the condition above, is the output correct?
# 28  
Old 02-22-2012
output wanted:

cd /PATH
svn relocate OldRepo NewRepo

Code:
example
cd AgentWebPages/AgentWebPages/Source/Distrib
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ePDS2 https://svnprod.nwie.net/svn/ePDS2

Seems to work except when Input file has spaces in the PATH/directory Name/
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concatenate two variables and form the third variable

Hi Guys, I was scratching my head for this for half a day... finally not successful :confused: Following is the problem I have a variable $ var1=123 $ var2-234 $ var3=345 and another Variable $ i=1 Now i wanted to save these into a Variable as shown below for i in 1 2 3 do... (5 Replies)
Discussion started by: ramprabhum
5 Replies

2. UNIX for Dummies Questions & Answers

Formating variables in KSH

Hi Friends , I want to know how to format the output for the following: i searched in the forum and couldnt get the exact requirement. Thanks in advance . (2 Replies)
Discussion started by: i150371485
2 Replies

3. Shell Programming and Scripting

concatenate variables

I need to know how to concatenate variables in Debian. I am making a interactive script where it ask the user for info to add a user I pull the first letter from the first middle and last name into individual variables now i want to put them all in one variable so i can put it into useradd command ... (4 Replies)
Discussion started by: HackerSeabass
4 Replies

4. Shell Programming and Scripting

ksh - for loop with variables

Hi, I 'm trying to send an e-mail for every different line in the .txt for i in {1..$variable} do sed -n "/$i$/p" text.txt done I have two problems about this. First one is that for loop doesn't work and the second one is that i cant get the output of sed (4 Replies)
Discussion started by: ozum
4 Replies

5. Shell Programming and Scripting

concatenate variables problem

Hello, I have a tricky problem: I have a $file with a variable number of occurrences of "ORA-" (in this case two) .......... EXP-00008: ORACLE error 3113 encountered ORA-03113: end-of-file on communication channel EXP-00056: ORACLE error 1403 encountered ORA-01403: no data found... (9 Replies)
Discussion started by: Laurentiu
9 Replies

6. Shell Programming and Scripting

Combining two variables in ksh

I can't believe I can't figure this out... given this code: CARS_DATA_LIST=`cat /tmp/file1 | awk '{print $1}' ` FMSA_DATA_LIST=`cat /tmp/file2 | awk '{print $1}' ` The value of each of the above variables is: CARS = a b c d e f g FMSA = a b c q r s I want to declare a third... (8 Replies)
Discussion started by: Shoeless_Mike
8 Replies

7. Shell Programming and Scripting

How to preserve NL in Ksh variables?

I'm trying to set a variable to the output of a command. This is what the comand output to the display looks like: />hciconndump -v TOsiu Dump of connection(s): TOsiu ---------------------------------------------------------------------- Process: A60Tsiu Connection: TOsiu... (2 Replies)
Discussion started by: troym72
2 Replies

8. Shell Programming and Scripting

how to concatenate values of two variables with an underscore(_) in between

Hi, I'm new to shell programming. I have two variables a and b a=val1 b=val2 could anyone kindly post the shell script to concatenate the values of variable a and b with an underscore(_) in between? The final output should be val1_val2. (8 Replies)
Discussion started by: badrimohanty
8 Replies

9. Shell Programming and Scripting

subtracting variables in ksh

hi all, how do i subract variables in shell ?? am trying to space out the headers and the output generated by the shell so they all line up : currently the output is like this : servers : users server1 : 10 latestServer : 50 so i thought... (3 Replies)
Discussion started by: cesarNZ
3 Replies

10. Shell Programming and Scripting

variables in ksh

I'm new to unix scripting. How would I go about pulling the first 3 characters from a variable in ksh and storing in another variable? Thanks. (9 Replies)
Discussion started by: steve6368
9 Replies
Login or Register to Ask a Question