problems getting a segment from a string output

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problems getting a segment from a string output
# 1  
Old 10-22-2009
problems getting a segment from a string output

I'm creating a script that creates files from svn checkout and compress them using tar.gz

the script gets the repository name from command line argument

i need to capture a number from the last line of the output and create a file name from it.

the svn returns output of all the file names from the repository and in the end it says:
revision number xxxxx

i need to get this number and then rename the tar.gz to it

how do i save the output to a variable and get this number

this is the script:

svn co svn://$1 temp && tar czf backup.tar.gz temp

# 2  
Old 10-22-2009
You can capture the revision number with:

variable=$(svn <options> | awk 'END{print $3}')

# 3  
Old 10-23-2009
and what about the tar?

thanks for your help!
i just need to know now how to keep running the tar command after the svn checkout , otherwise it start working without waiting for the svn checkout to work.
# 4  
Old 10-23-2009
You could try :
revnr=$(svn co svn://$1 temp |sed -n 's/Checked out.* //p')&& [ "$revnr" != "" ] && tar czvf /tmp/test.${revnr}tar.gz --exclude=.svn temp

I added --exclude=.svn
You can leave out this option if you want to include the subversion information....
# 5  
Old 10-23-2009
wow thanks!

that's look like it would solve this case Smilie

i don't really understand everything in that script. i need to learn more.

You got some good documents with examples that i can improve my knowledge ?
# 6  
Old 10-23-2009
Hi tvio, you're welcome..

A little explanation:
revnr=$(svn co svn://$1 temp |sed -n 's/Checked out.* //p')

This is the same a what Franklin52 suggested, just the technique of extraction the version string is different. The result is put in the variable revnr. The return code is the return code of the assignment and not that of the checkout so it is always 0. So in fact the first && is bogus and a "; " could also have been used instead. Since we do not have a return of the checkout we need to test the result:
[ "$revnr" != "" ]

If the variable is non-empty then the checkout was successful so we can go ahead with the tar.

As to your question about the information, IMO an O'Reilly book on your favorite shell (hint: pick ksh, pick ksh...) is usually a good place to start, but I am sure there are plenty of online resources...

Last edited by Scrutinizer; 10-23-2009 at 08:13 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problems with one line output

my echo $var1 gives below value 1.7_NEW=25,1.7_RETAINED=30,1.7_RETURNING=40 i want it in 3 different values.... i.e. as echo $1.7_NEW=25 echo $1.7_RETAINED=30 echo $1.7_RETURNING=40 the o/p of $1.7_NEW should be 25..... (5 Replies)
Discussion started by: nikhil jain
5 Replies

2. Shell Programming and Scripting

String comparison problems

Req: =========== 1)I have one shell script 2)I opened Putty session , with user name = SIR100 , and i ran script in back ground and it took 5 minutes to complete.Meanwhile,i ran same script second time i.e with same user it sholud not allow to run the script , but it's... (3 Replies)
Discussion started by: as234301
3 Replies

3. Programming

Data segment or Text segment

Hi, Whether the following piece of code is placed in the read-only memory of code (text) segment or data segment? char *a = "Hello"; I am getting two different answers while searching in google :( that's why the confusion is (7 Replies)
Discussion started by: royalibrahim
7 Replies

4. Shell Programming and Scripting

String concatenation problems

#! /bin/csh set tt=12345_UMR_BH452_3_2.txt set rr=`echo $tt | cut -d_ -f1` set rr1=welcome set ff=$rr $rr1 echo $ff why $ff returned only 12345 and not 12345welcome? thanks (2 Replies)
Discussion started by: jdsignature88
2 Replies

5. Shell Programming and Scripting

awk: round output or delimit output of arithmatic string

I have a file with the following content. > cat /tmp/internetusage.txt 6709.296322 30000 2/7/2010 0.00I am using the following awk command to calculate a percentage from field 1 and 2 from the file. awk '{ print $1/$2*100 }' /tmp/internetusage.txt This outputs the value "22.3643" as a... (1 Reply)
Discussion started by: jelloir
1 Replies

6. Shell Programming and Scripting

My output Problems

jnkjhjkhbjkhb (1 Reply)
Discussion started by: vinayrao
1 Replies

7. Shell Programming and Scripting

how to find a particular string from a set of string output

Hi , I have a line by line output as follows,for example output of ls sample1 sample2 sample i need to check if this output contains the exact string sample.If i use grep , it will find out all strings that contain sample as a part of their word.I dont want to do a pattern matching... (11 Replies)
Discussion started by: padmisri
11 Replies

8. Shell Programming and Scripting

Cutting segment of a string

Hi, I am using bash. My question concerns cutting out segments of a string. Given the following filename: S2002254132542.L1A_MLAC.x.hdf I have been able to successfully separate the string at the periods (.): $ L1A_FILE=S2002254132542.L1A_MLAC.x.hdf $ BASE=$(echo $L1A_FILE | awk -F.... (5 Replies)
Discussion started by: msb65
5 Replies

9. UNIX for Advanced & Expert Users

Help please...output problems with printf.

#include <stdio.h> #include <math.h> // this function calculates the volume of a Cylinder int main(void) { int r; // radius int h; // height double M_PI; // pi int pOne = pow (r, 2); // get user input of radius and height printf ("Enter your... (3 Replies)
Discussion started by: pwanda
3 Replies

10. Shell Programming and Scripting

problems egreging for a '(0)' string

Hi, I'm trying to egreg for a couple strings whcih are (0) and SYSTEM. The problem is the syntax for egreg is: egreg "(string1|string2)" With my basic knowledge of UNIX I don't know how to include '(0)' within "(string1|string2)" apart from trying to use single quotes which doesn't work,... (9 Replies)
Discussion started by: m223464
9 Replies
Login or Register to Ask a Question