Help cannot concatenate Ksh variables ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help cannot concatenate Ksh variables ?
# 36  
Old 02-23-2012
SECOND SCRIPT. still contains original errors. Suggested changes in red.
Code:
#!/bin/ksh
#################################################################################
# This script uses grep and gets the working copy locations from the dnaRelowc1.dat file                            #
# and creates a script with the relocate command to relocate DNA build working copies from                      #
# the  svn01g.gdc.net server to the svnprod.nwie.net server.                                                                                #
#################################################################################
#
# Read the list of Subversion working copies directories to Relocate to new Subversion Server
OutputLoc="/scripts/dataout"
bldDirLoc="/webdata/tmpDNAbld/"
wcfiles=${OutputLoc}/dnaRelwc2.dat  
svnRelcmd="svn relocate"
set svnRelcmd

cd ${bldDirLoc}

cat "${wcfiles}" | while read i
do
    #get current host URL from each entries file
    OldRepo=`grep svn01g.gdc ${i}/.svn/entries | tail -1`
    #Replace each current host URL with New host URL
    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'`
    #print line to change directory to each directory that contains the .svn(dotsvn) subdirectory (cd PATH)
    echo "cd $i"
    #print next line to execute command in each directory (svn relocate OldRepo NewRepo)
    echo "$svnRelcmd $OldRepo $NewRepo"
done

Apart from the form-feed characters which show as "\f" the input file looks ok.
The overwriting on the screen was caused by the "\c" in the "echo -e".

Last edited by methyl; 02-23-2012 at 10:50 AM.. Reason: fix layout
This User Gave Thanks to methyl For This Post:
# 37  
Old 02-23-2012
Quote:
Originally Posted by methyl
FIRST SCRIPT last line does not work at all (due to the backticks) and appears to write to the input file dnaRelwc1.dat when the next script actually reads dnaRelwc2.dat.
Perhaps you meant:
Code:
cat ${OutputLoc}/dnaRelwc1.txt | sort -u | cut -c3- >${OutputLoc}/dnaRelwc2.dat

That explains where the output file comes from!
when ran numbers are the same. what was cut and pasted was mixed. the numbers reflect suggested variations.

The script does work I run it manually without the ticks

I already know where the the output files comes from just need the final file to be formatted correctly

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

I know the code works because the first file has ./ in the front of each line the output file does not

---------- Post updated at 11:57 AM ---------- Previous update was at 10:59 AM ----------

Quote:
Originally Posted by methyl
SECOND SCRIPT. still contains original errors. Suggested changes in red.
Code:
#!/bin/ksh
#################################################################################
# This script uses grep and gets the working copy locations from the dnaRelowc1.dat file                            #
# and creates a script with the relocate command to relocate DNA build working copies from                      #
# the  svn01g.gdc.net server to the svnprod.nwie.net server.                                                                                #
#################################################################################
#
# Read the list of Subversion working copies directories to Relocate to new Subversion Server
OutputLoc="/scripts/dataout"
bldDirLoc="/webdata/tmpDNAbld/"
wcfiles=${OutputLoc}/dnaRelwc2.dat  
svnRelcmd="svn relocate"
set svnRelcmd

cd ${bldDirLoc}

cat "${wcfiles}" | while read i
do
    #get current host URL from each entries file
    OldRepo=`grep svn01g.gdc ${i}/.svn/entries | tail -1`
    #Replace each current host URL with New host URL
    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'`
    #print line to change directory to each directory that contains the .svn(dotsvn) subdirectory (cd PATH)
    echo "cd $i"
    #print next line to execute command in each directory (svn relocate OldRepo NewRepo)
    echo "$svnRelcmd $OldRepo $NewRepo"
done

Apart from the form-feed characters which show as "\f" the input file looks ok.
The overwriting on the screen was caused by the "\c" in the "echo -e".
Better the cd PATH now includes the spaces in directory names
but the line below that has svn relocate does not include OldRepo NewRepo
the actual input file and output file no snip are large you want posted here ?
# 38  
Old 02-23-2012
Quote:
I know the code works because the first file has ./ in the front of each line the output file does not
On my test (after removing the backticks) the output file blanked the input file because they had the same name. There is a warning about this in "man cat".
# 39  
Old 02-23-2012
Staring me in the face. Need some more quotes for the grep and thinking ahead you'll need quotes on the final output lines. All because the filenames contain space characters.
Code:
#!/bin/ksh
#################################################################################
# This script uses grep and gets the working copy locations from the dnaRelowc1.dat file                            #
# and creates a script with the relocate command to relocate DNA build working copies from                      #
# the  svn01g.gdc.net server to the svnprod.nwie.net server.                                                                                #
#################################################################################
#
# Read the list of Subversion working copies directories to Relocate to new Subversion Server
OutputLoc="/scripts/dataout"
bldDirLoc="/webdata/tmpDNAbld/"
wcfiles=${OutputLoc}/dnaRelwc2.dat  
svnRelcmd="svn relocate"
set svnRelcmd

cd ${bldDirLoc}

cat "${wcfiles}" | while read i
do
    #get current host URL from each entries file
    OldRepo=`grep svn01g.gdc "${i}"/.svn/entries | tail -1`
    #Replace each current host URL with New host URL
    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'`
    #print line to change directory to each directory that contains the .svn(dotsvn) subdirectory (cd PATH)
    echo "cd \"$i\""
    #print next line to execute command in each directory (svn relocate OldRepo NewRepo)
    echo "$svnRelcmd \"$OldRepo\" \"$NewRepo\""
done

This User Gave Thanks to methyl For This Post:
# 40  
Old 02-23-2012
I'll try that previously I used nawk to "add" quote to the input file but the output file was still broken. I'll make you changes and let you know

---------- Post updated at 01:04 PM ---------- Previous update was at 12:32 PM ----------

Quote:
Originally Posted by methyl
Staring me in the face. Need some more quotes for the grep and thinking ahead you'll need quotes on the final output lines. All because the filenames contain space characters.
Code:
#!/bin/ksh
#################################################################################
# This script uses grep and gets the working copy locations from the dnaRelowc1.dat file                            #
# and creates a script with the relocate command to relocate DNA build working copies from                      #
# the  svn01g.gdc.net server to the svnprod.nwie.net server.                                                                                #
#################################################################################
#
# Read the list of Subversion working copies directories to Relocate to new Subversion Server
OutputLoc="/scripts/dataout"
bldDirLoc="/webdata/tmpDNAbld/"
wcfiles=${OutputLoc}/dnaRelwc2.dat  
svnRelcmd="svn relocate"
set svnRelcmd

cd ${bldDirLoc}

cat "${wcfiles}" | while read i
do
    #get current host URL from each entries file
    OldRepo=`grep svn01g.gdc "${i}"/.svn/entries | tail -1`
    #Replace each current host URL with New host URL
    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'`
    #print line to change directory to each directory that contains the .svn(dotsvn) subdirectory (cd PATH)
    echo "cd \"$i\""
    #print next line to execute command in each directory (svn relocate OldRepo NewRepo)
    echo "$svnRelcmd \"$OldRepo\" \"$NewRepo\""
done

Drops OldRepo NewRepo after PATH with spaces in name
Code:
cd "ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/obj/Release" 
svn relocate "" "" 
cd "nfoInProc/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" "https://svnprod.nwie.net/svn/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 "" ""

---------- Post updated at 01:30 PM ---------- Previous update was at 01:04 PM ----------

and i verified that
"ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/My Project"
contains ,svn/entries.

However what is different is that the URLpath has %20 for spaces in the list as it should

---------- Post updated at 01:35 PM ---------- Previous update was at 01:30 PM ----------

so grep sees this but we only need the second line
Code:
https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS/release_ready/Utility%20EXE%20Attachment/DotNET/My%20Project
https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS

not sure this is having an affect or not

Last edited by methyl; 02-23-2012 at 02:54 PM.. Reason: fix code tag
# 41  
Old 02-23-2012
The string "ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/My Project" does not occur in the data posted (with or without %20). Perhaps this the the wrong data? Also, no part of the string matches any part of the second url.

Code:
https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS/release_ready/Utility%20EXE%20Attachment/DotNET/My%20Project
https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS

Overall, yes I do believe that the %20 will be a major factor because the two grep commands need to find the exact unix path name in the .svn file.

At the moment there is such a discrepancy in the data that the ball is back your court to check the data.
# 42  
Old 02-23-2012
yes it does look at the second to last line in code above last line below

The cd "..." is the directory location where the .svn Directory lives and where the svn relocate command needs to be executed in.

The URL is extracted from the "entries" files that is under the .svn Directory and used in the svn relocate command line.

Drops OldRepo NewRepo after PATH with spaces in name

Code:
cd "ALPS_ATTACHMENT/Utility EXE Attachment/DotNET/obj/Release"
svn relocate "" ""
cd "nfoInProc/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" "https://svnprod.nwie.net/svn/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 "" ""

the string is in the "entries" file in the .svn directory like all the others. that is where I got the two lines above.

---------- Post updated at 03:14 PM ---------- Previous update was at 03:11 PM ----------

Thanks for all your help

---------- Post updated at 03:54 PM ---------- Previous update was at 03:14 PM ----------

FYI if I do this manually I get the correct answer:
Code:
$ grep svn01g.gdc "ALPS_ATTACHMENT/Utility EXE Attachment"/.svn/entries 
https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS/release_ready/Utility%20EXE%20Attachment 
https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS

---------- Post updated at 03:58 PM ---------- Previous update was at 03:54 PM ----------

so the output needed would be:
Code:
cd "ALPS_ATTACHMENT/Utility EXE Attachment"
svn relocate https://svn01g.gdc.nwie.net/svn01p/svn/Repositories/ALPS https://svnprod.nwie.net/svn/ALPS

---------- Post updated at 05:13 PM ---------- Previous update was at 03:58 PM ----------

there are over 5000 lines (Paths) in the input file seem only a couple hundred somehoe got missed by grep for what ever reason. I am fixing those manually. Overall I'd say the data was very consistant. and I appreciate all you help. Even with the manual part it more than likely saved lots of time as will the resulting script. what is cool is if I reverse the OldRepo and NewRepo it provides a backout script encase there is a problem

Last edited by pcpinkerton; 02-24-2012 at 06:06 AM..
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