The UNIX and Linux Forums  


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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 02-11-2009
fedora fedora is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 94
Thanks, I know in this example I gave, egrep is a better choice, but actually my real work is "finding out both "user" and "nas" part, and then print out the result.

below is the result I want

+
user_a nas_b
user_d nas_b
user_a
user_c nas_m
+

But the problem is, no matter how i modified my script, I just won't get the desired result...

[QUOTE=radoulov;302286540]With awk:


Code:
awk '{ 
  for (i=1; i<=NF; i++)
    if ($i ~ /user/)
      print $i
      }' infile

With Perl: