The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using first word and print their contents using awk cdfd123 Shell Programming and Scripting 6 10-10-2007 04:12 AM
search for the contents in many file and print that file using shell script cdfd123 Shell Programming and Scripting 3 10-07-2007 11:17 PM
ls command to print fifo of contents (or perl) jerardfjay Shell Programming and Scripting 1 04-06-2006 03:01 PM
Creating file contents using contents of another file ReV Shell Programming and Scripting 21 02-24-2006 10:25 AM
How to print contents on the screen? aadba UNIX for Advanced & Expert Users 1 03-22-2004 10:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 08-07-2008
rmsagar rmsagar is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 3
awk - print file contents except regex

Hello,
I have a file which has user information. Each user has 2 variables with the same name like
Email: testuser1
Email: testuser1@test.com
Email: testuser2
Email: testuser2@test.com
My intention is to delete the ones without the '@' symbol. When I run this statement awk '/^Email:/&&!/@/' <FileName>. It prints all the Email variable without the @. But when I try to run this one expecting to print all the lines except Email without @. it prints everything.
awk '/cn:/&&!/@/ { copy=1 }; copy { print } ' <filename>

Please advise.

-Regards,
  #2 (permalink)  
Old 08-07-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753

Code:
awk '/^Email/ && /@/' file

gives you only the lines that have the @ symbol embedded in them.
  #3 (permalink)  
Old 08-07-2008
sudhamacs sudhamacs is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 98
grep "@" filename > filename2
  #4 (permalink)  
Old 08-07-2008
rmsagar rmsagar is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 3
There are other lines which I would like to print/list

If the File contains

First Name: Test
Last Name: User1
Email: testuser1
Email: testuser1@test.com

after running awk I would that to be print as

First Name: Test
Last Name: User1
Email: testuser1@test.com
  #5 (permalink)  
Old 08-07-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753

Code:
awk '!(/^Email/ && !/@/)' file

  #6 (permalink)  
Old 08-07-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,440

Code:
awk '/^Email/ && ! /@/' file

  #7 (permalink)  
Old 08-09-2008
rmsagar rmsagar is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 3
Thanks shamrock. Exactly as expected.

Thanks everyone.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0