Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi again, I need to get a string from a file and can't figure out how to grep it.
This file is from a subversion commit. Its always of the form
X project/sub1/sub2/sub3/filename1.ext
X project/sub1/sub2/sub3/filename2.ext
X project/sub1/sub2/sub3/filename3.ext
X is an operation. There will be at least 1 line.
All I need is it to return is the text "project" in this example from first line.
So its something like "in the first line, get the string starting at the end of the first set of spaces up but not including the next "/" you hit. Ignore all other lines. Thanks in advance
awk is going to be better than grep and I can find a simple command for you later when I get home (if no one else can punch one out). If you are impatient or just want to learn... `man awk`
But my real reason for posting this. Did you go to FIT and do you want to be a Vegas showgirl? Sorry if these questions seem weird but I think I either know you or you share a name with someone I know.
Hi Man, nahh, you got the wrong guy there - sorry!
The command is real close but not quite right.
Used as you wrote, I get "warning escape sequence '\/' treated as plain '/' then the whole path without the X part.
I tried changing the FS to [\\/] and the warning went but the rest of the path still appeared:
project/sub1/sub2/sub3/filename1.ext
Thanks for your help
Last edited by ericcarlson; 07-17-2004 at 05:02 AM.
That might work or it might not... it is really hard to test these things when you are at a windows box. As far as I can tell that should define two seperate field seperators and not one of " /" but I could be wrong. I didn't know if I needed to escape the / so I did it out of caution.
lol, I didn't know if you were him. But I had to ask.
EDIT: If that doesn't work I will try it when I get home... but that will be after 11am EDT.
I saw an awk example that was nearly the same so picked up the BEGIN.
Using just one grep with [ /] gave a blank line. Youre doing better than me and im at a linux box!!
Although I had to smack myself in the forehead when I saw the solution... why was I so determined to do it in one go? Of course grabbing it like you did makes more sense.
head changed-files.txt -n 1 | gawk 'BEGIN {FS="[ \t]*|[/]"}{print $2}'
Okay, I couldn't admit to myself that I was really going down the wrong path. The above solves the problem in one sweep of awk... with the added bonus of accepting whatever amount of spaces or tabs might be between the first field and the rest as one seperator. Just in case the file format should change.
I know... I shouldn't have bothered. I just knew it could be done... just took some figuring and some time at the prompt.
Although you got it working, I thought I'd mention an alternative to head:
"grep -m 1 project" will grep project and stop after the first instance is found. This is useful in case you have something different on the first line of the file (such as a comment or a #!)
The thing is, as I understand it, the file is in that format but the directory "project" may change dependant on the project the file is for. Of course I could be wrong and maybe he just wanted code to spit out the word project.
The log file is produced buy a hook script on a subversion commit.
What I am doing is automating java builds on source checkin. Its working now ;-)
You are right about the "project" part being the only variable amongst multiple projects.
All I needed was that field, the subversion log is a little limited in this respect but no matter with you guys around ;-) Its fired on checkin, so I do the magic and feed it into the various ant tasks to build the .jars. I know java well, and subversion, just not too hot on bash scripting even though I knew exactly what I needed it to do.
Oh, its also gonna be used as a cron job for overnight builds.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.