The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
doubt regardin regex in grep evergreen_cool Shell Programming and Scripting 4 09-02-2008 06:57 PM
grep with Regex help! mvalonso UNIX for Dummies Questions & Answers 3 06-01-2007 12:36 PM
Problem with grep Regex Error lweegp Shell Programming and Scripting 6 11-16-2006 12:04 AM
grep regex problem iceman Shell Programming and Scripting 2 02-06-2005 08:44 AM
use of regex on grep solea UNIX for Dummies Questions & Answers 0 09-30-2004 08:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-25-2008
Registered User
 

Join Date: Mar 2008
Posts: 11
Help with grep and regex

Hi all,

I'm a beginner with linux, regex, grep, etc
I am trying to get data out of a file that has about 13,000 lines in this format

name - location

I want to grep all the names out to one file and the locations to another so I can put them into a spreadsheet.

Some have hyphenated names or hyphenated locations as well to complicate things.

The way I was going to approach it was to first grep out the lines with only one hypen to one file and all the ones with multiple hyphens to another.

Then I need an expression to select all data on one side of the hyphen and place it into one file, and the data on the other side of the hyphen into another file.

I'm going through all the tutorials I can find, but they don't read much better than man pages and I can't figure out how to do what I want. Can anyone help me get started with this?


Thanks in advance!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-25-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
sed -e 's/ - /	/'
That's a tab behind the second slash. Assuming you have a space on both sides of the divider dash, and not too many dashes with spaces on both sides which are not dividers, this should pretty much solve the issue. Probably your spreadsheet (yuck) can even handle tab-delimited input.

Next up, read the manual for the "cut" command.
Reply With Quote
  #3 (permalink)  
Old 03-25-2008
Registered User
 

Join Date: Mar 2008
Posts: 11
well that removed all the hyphens between name and location WITHOUT removing the words that needed to be hyphenated, so that's a start, but it still doesn't allow me to separate the data on either side of the delimiting hyphen... Unless I did something wrong.. I typed:

sed -e 's/ - / /' list > list2

Thanks!

Oh wait, I see where you were going...

The problem now is that there are spaces in names and locations, and this appears to have placed a space between the data. Not enough to separate the data logically, at least for Calc.
Reply With Quote
  #4 (permalink)  
Old 03-25-2008
Registered User
 

Join Date: Mar 2008
Posts: 11
I changed the command to read
sed -e 's/ - / % /' list > list3

and now I have a separate symbol to break up the data. Is there an expression to say cut all data up to the % and write to a file?
Reply With Quote
  #5 (permalink)  
Old 03-25-2008
Registered User
 

Join Date: Mar 2008
Posts: 11
got it, thanks.

The answer was to use cut as such:

cut --delimiter='%' -f 1 list3 > name
cut --delimiter='@' -f 2 list3 > location

Thanks for the help!
Reply With Quote
  #6 (permalink)  
Old 03-26-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
A tab is a more conventional separator character, although of course it looks like just whitespace.

To type a tab at the command line, you often need to use some escape code, like ctrl-v tab to get a literal tab.
Reply With Quote
  #7 (permalink)  
Old 04-14-2008
Registered User
 

Join Date: Mar 2008
Posts: 11
sigh... still working on this.

There are 2 more things I have to figure out. .

How do you indicate all lines beginning with specific file paths for example:

A/A/*

sed -e 's/"A/A/*"/ /g' > newfile

doesn't seem like it's going to work...

And how do I indicate a blank line?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux, regex, regular expressions

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0