Grep usage help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep usage help
# 1  
Old 05-29-2008
Grep usage help

Hello,

I have a list in .txt format of email addresses and I need to extract just a specific domain ...

The list format is like:
"123456";"user@domain.com";"email";"john";"name"
"123457";"user2@domain.com";"email";"john";"name"
"123458";"user3@domain.com";"email";"john";"name"
"123459";"user4@domain.com";"email";"john";"name"

After running grep I want the newly created list to look like:
user@domain.com
user2@domain.com
user3@domain.com
user4@domain.com

I tried grep -r @domain.com filename1.txt > filename2.txt

It works but gives me all the things before and after the email address, I just want the email by itself...


Thanks in advance for your help!!!!!!!!!
# 2  
Old 05-29-2008
You could use awk instead:
Code:
awk -F"\";\"" '{print $2}' file

# 3  
Old 05-29-2008
Code:
awk -F'";"' '{ print $2 }' input_file.txt

# 4  
Old 05-29-2008
Hello,

I tried both your commands but they didn't work ...

I tried it on gawk in windows:

C:\TEMP\LIST>awk -F'";"' '{ print $2 }' bad1txt > bad2.txt
awk: '{
awk: ^ invalid char ''' in expression

C:\TEMP\LIST>awk -F"\";\"" '{print $2}' bad1.txt > bad2.txt
awk: '{print
awk: ^ invalid char ''' in expression


Any idea?
# 5  
Old 05-29-2008
Strange. Maybe a Windows peculiarity. Try:

Code:
sed -r 's/^.+;"([^@]+@[^"]+)".+/\1/' file

# 6  
Old 05-29-2008
Are you using Windows Services for UNIX?

I've used them in the past and I remember I had your same issue... Don't remember if it was something related to single/double quotes escaping or curly braces... Try escaping them with a backslash or playing around with quoting... Or try another approach:

Code:
cut -f2 -d ';' input_file.txt | cut -f2 -d '"'

...or try a real linux emulation like cygwin, which is better.

EDIT: paying more attention to the error returned, now I seem to remember that awk on windows does not like single quotes around the awk script: you must always use double quotes, and escape all the double quotes that now are surrounded by single quotes, like ripat did in the post before. Try something like this:

Code:
awk -F"\";\"" "{ print $2 }" input_file.txt


Last edited by robotronic; 05-29-2008 at 03:46 PM..
# 7  
Old 05-29-2008
Code:
cut -d "\"" -f4 < file > outfile

Regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Usage of grep '^$1' filename

There is a file name list_filenames.dat, this has all the list of all files I need to encrypt, I did not understand what the following syntax is doing: grep -s "^$1" list_filenames.dat, when I manually run this command it just returns all the lines, what is the usage of this ? can someone... (4 Replies)
Discussion started by: okkadu
4 Replies

2. Homework & Coursework Questions

grep usage help?

Use and complete the template provided. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have to find all the files where the function sequentialInsert is called and the directory is ~cs252/Assignments/commandsAsst/project 2.... (2 Replies)
Discussion started by: jennkat
2 Replies

3. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

4. Shell Programming and Scripting

grep command usage

what is the grep command to get the second occurence of pattern in a file or how to do with sed ? (1 Reply)
Discussion started by: santosh1234
1 Replies

5. Shell Programming and Scripting

Problems in Usage of grep

Hi all, I have a file resp_cde.ats which has values as:- APPDIR=C:\Program Files\Cogny\cert PUBSDIR=C:\Program Files\Cognoy\cert\documentation TOURDIR=C:\Program Files\Cognoy\cert\tour DATADIR=C:\Program Files\Cognoy\cert\data Now I use the grep command in a shell script:- x=`grep... (2 Replies)
Discussion started by: vikasrout
2 Replies

6. UNIX for Advanced & Expert Users

Grep usage

my file contains xxabced.p dlksfad; dflsdkjflkds flksdjflkdioewf erfsdlkfjsdla; dlkfjsd;lfkj msgdadf.p dslk kdjflksdjfl;asdfasdfjkljl fdsf;jd ppuskldf.p i want the output is xxabced.p msgdadf.p ppuskldf.p Can any one give the command? (1 Reply)
Discussion started by: kingganesh04
1 Replies

7. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

8. UNIX for Dummies Questions & Answers

Grep Usage

Hello, I am trying to use grep to locate multiple uses of the same word in the same line. The word has to be 3+ char, upper or lower or both. I tried this code <code> grep \({3,}\)*\1 i* </code> and i turned out zero results. Any ideas? ____________________________________________... (5 Replies)
Discussion started by: Omega1589
5 Replies

9. UNIX for Advanced & Expert Users

grep usage

grep can filter the text which want to display, but if I want it do not show the text specific in grep, how to do? thk a lot! (2 Replies)
Discussion started by: zp523444
2 Replies

10. UNIX for Dummies Questions & Answers

grep Vs CPU usage

Hi, I have one basic doubt, that using grep command frequently , will it have direct impact on the CPU load, pls clarify for eg, if i run a non stop script containing while loop to grep some parameters, what will be the load in CPU.. thanks (3 Replies)
Discussion started by: vasikaran
3 Replies
Login or Register to Ask a Question