LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-12-2009, 07:45 AM   #1
newbiescripter
LQ Newbie
 
Registered: Jun 2009
Posts: 3

Rep: Reputation: 0
shell scripting question


Hello,

I have a shell scripting question that I have been unable to track down an answer to and the things I have tried do not seem to work.

We are using subverion as our repository and I need to extrapolate information out of the repository and build a file with the information returned in a specific format.

I have managed the following:

svn log -vq -r${revision} ${repository} | egrep '^ {3}[AMR] ' | cut -c6- | sort | uniq > ${myFile}

This will dump to a file all the elements within a specific revision. Then for each record in the file, I the svn list -v command passing the element.

The problem I am having is being able to parse the string returned by the 'svn list' command into its separate pieces. I have included a basic example of what I am trying to do and the problem I am having.

Example:

Code:
elemVar=`svn list -v ${myElement}`
sizeVar=`svn list -v ${myElement} | cut -d' ' -f 21`
verVar=`svn list -v ${myElement} | cut -d' ' -f 7`
userVar=`svn list -v ${myElement} | cut -d' ' -f 8`
dateVar=`svn list -v ${myElement} | cut -d' ' -f 22-24`
nameVar=`svn list -v ${myElement} | cut -d' ' -f 25`

printf "${elemVar}\n" >> mmm.txt
printf "${sizeVar}\n" >> mmm.txt
printf "${nameVar}\n" >> mmm.txt
printf "${verVar}\n" >> mmm.txt
printf "${dateVar}\n" >> mmm.txt
printf "${userVar}\n" >> mmm.txt
printf "\n\n\n" >> mmm.txt


Output (mmm.txt):
PHP Code:
      1 root              196 Jun 09 13:48 ABCD-ZZZZZZZ.G
 
13
:48
1
196 Jun 09
root
 
 
      1 root              147 Jun 09 13
:48 ABCD-BB.G
 
13
:48
1
147 Jun 09
root
 
      1 root             9999 Jun 09 13
:48 ABCD-NNNNN.G
9999
ABCD
-NNNNN.G
1
Jun 09 13
:48
root 
 
      1 root             1748 Jun 09 13
:48 ABCD-ABCD.G
1748
ABCD
-ABCD.G
1
Jun 09 13
:48
root 
My apologizes me for formatting the information as PHP, but it was the only way I could get all the spaces to be reflected correctly.

As you can see, if the file size is 4 characters long (i.e. 9999), then all the fields parse correctly, otherwise they do not.

I tried reading about some of the commands in shell scripting, but I could not put together anything that would do what I needed.

Also, I am wondering if there is any kind of command to convert the Jun 09 date to 2009-06-09?

Any help you can offer would be most appreciated.

newbiescripter
 
Old 06-12-2009, 08:25 AM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 164Reputation: 164
Can I see a chunk of the data contained in myfile?
 
Old 06-12-2009, 08:42 AM   #3
newbiescripter
LQ Newbie
 
Registered: Jun 2009
Posts: 3

Original Poster
Rep: Reputation: 0
It contains a listing of the items in the repository -- looks like the following:

/baseline
/baseline/data
/baseline/data/ABCD-ZZZZZZZ.G
/baseline/data/ABCD-BB.G
/baseline/data/ABCD-ABCD.G
/baseline/data/ABCD-NNNNN.G
 
Old 06-12-2009, 10:05 AM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by newbiescripter View Post
The problem I am having is being able to parse the string returned by the 'svn list' command into its separate pieces.
Use "sed" to convert groups of spaces to a comma, and use the comma character as your field delimiter in your "cut" commands:
Code:
sizeVar=`svn list -v ${myElement} | sed -e 's/  */,/g' | cut -d',' -f 21`
 
Old 06-12-2009, 11:14 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 200Reputation: 200Reputation: 200
it's easy to split, use read which will split on
whitespace:

Code:
# echo 1 2 3|                                       
while read x y z
do
echo $z $y $x
done

3 2 1
 
Old 06-18-2009, 03:20 PM   #6
kike_coello
Member
 
Registered: Jul 2005
Location: maryland
Distribution: Ubuntu 9.04
Posts: 88

Rep: Reputation: 17
about the date problem, you know that the month and day are on the 4th and 5th fields so why not write a small script that will take those 2 fields and replace it with the format you want, you already know that this files are recent so you can safely assume that they are 2009, then all you are going to be replacing are the month with a case statement. after that, you use a replacement on your input file with sed, hope that helps

Enrique
 
Old 06-19-2009, 02:06 AM   #7
sreeharsha.t
Member
 
Registered: Jan 2009
Location: Mumbai, India
Distribution: Fedora 9, 10,11, RHEL 5
Posts: 67

Rep: Reputation: 18
Question

I found the following lines in a networking script used by Xen.

netdev=${netdev:-$(ip route list 0.0.0.0/0 | \
sed 's/.*dev \([a-z]\+[0-9]\+\).*$/\1/')}

I understood that it is trying to assign 'netdev' the interface having the default route. But what I don't understand is why is it given as
Quote:
netdev=${netdev:-$(ip ....)}
Can't it be simply written as netdev=$(ip route list 0.0.0.0/0 | \
sed 's/.*dev \([a-z]\+[0-9]\+\).*$/\1/')

What's making the difference here?

Also, is there any difference between $var and ${var} ?

Thanks.
Harsha
 
Old 06-19-2009, 02:19 AM   #8
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by newbiescripter

Also, I am wondering if there is any kind of command to convert the Jun 09 date to 2009-06-09?
newbiescripter
Maybe the date command while do that for you.
Code:
date -d "Jun 09" +"%Y-%m-%d"
2009-06-09
-d makes date to use the provided date for input (normaly it takes the machine date
the + start the output string. Beware the " without you'll get an error cause of the -.
Also make sure that you provide everything you need in the -d part else date use the machine date for not provided information
 
Old 06-19-2009, 05:32 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 200Reputation: 200Reputation: 200
${var} is the full syntax for $var

so you can do stuff like
${var}X which won't work as $varX of course
 
Old 06-19-2009, 06:26 AM   #10
newbiescripter
LQ Newbie
 
Registered: Jun 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks everybody for your input -- with it, I was able to get the script running correctly -- as for the date issue, I used the method described by zhjim:

dateVar=`date -d "$dateVar" '+%m/%d/%y %H:%M:%S'`
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell scripting question bhert Linux - General 2 01-29-2007 08:55 PM
shell scripting question creolophus Linux - Software 1 10-02-2006 02:13 AM
shell scripting question JSLayton Linux - General 4 06-01-2006 06:55 AM
Shell Scripting Question Onyx^ Linux - General 5 04-27-2004 10:37 AM
Shell Scripting Question b_vasu Linux - Newbie 1 11-21-2003 02:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration