Results 1 to 4 of 4
Hey, I know the title was too long but basically, what I'm trying to do is take a specific string from a text file and print the strings to a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-13-2010 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 35
Searching .txt file for (specific) strings and printing them to new file
Hey, I know the title was too long but basically, what I'm trying to do is take a specific string from a text file and print the strings to a seperate file and on a new line. May seem confusing but here's an example.
Name: Bob, PhoneNumber: *****, MobileNumber: *****, Email: ***@**.com,
And I have a file with this type of formatting; if I was using the above example, I would like to take only the Emails from the file and print them to a completely seperate file by > seperate-file.txt but the problem is, I don't know how to go about that.
I tried using grep to search for a string of "***@***.com" but that would only print the entire line including Name, PhoneNumber, etcetera and after reading the man pages, found out that it's for whole lines.
I was wondering if anybody knew of a command that I could do this with? It's beginning to give me a bit of a headache.
Thanks for any help in advanced.
- 02-13-2010 #2This assumesCode:
cut -d "," -f4 original_file > new_file
- comma is not used in the "datafields", only as a delimiter
- commas are set, even if the datafield(s) should be emptyYou must always face the curtain with a bow.
- 02-13-2010 #3
P.S.:
Writing "Name", "PhoneNumber", etc in every line is a waste of space.
But even worse, it makes parsing harder.
If you -for example- want to send emails to all these Email: fields, you would have to strip the "Email:" part first.You must always face the curtain with a bow.
- 02-13-2010 #4Just Joined!
- Join Date
- Dec 2008
- Posts
- 35
Great, I've managed to do it now. Thank you for your help.


Reply With Quote
