The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
How can i remove spaces in between the fields in a file dsravan Shell Programming and Scripting 3 09-26-2006 04:11 PM
Find null fields in file rahulrathod Shell Programming and Scripting 2 06-23-2006 04:17 AM
Delete spaces in between fields guiguy Shell Programming and Scripting 12 03-31-2006 09:38 AM
align several fields and fill spaces with zero DebianJ Shell Programming and Scripting 2 11-23-2005 07:51 AM
Strip leading and trailing spaces only in a shell variable with embedded spaces jerardfjay Shell Programming and Scripting 6 03-07-2005 02:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-21-2006
alfredo123 alfredo123 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 44
Find fields with no spaces in value

This is what I need to do

I have a file that has a field with values like this

1111 2222
3333 4444
55555 666
333333333
444444444

I need for my command to out put only those fields that do not have spaces in them. So my output for the above file would be

333333333
444444444


how do I go about this?
  #2 (permalink)  
Old 06-21-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
nawk 'NF==1' myFile
  #3 (permalink)  
Old 06-21-2006
alfredo123 alfredo123 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 44
Quote:
Originally Posted by vgersh99
Code:
nawk 'NF==1' myFile
Thanks man....it worked...

Wat is nawk??? I tried awk 'NF==1' myFile and tht worked too!
  #4 (permalink)  
Old 06-21-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
an 'N' in 'nawk' stands for 'New'.
  #5 (permalink)  
Old 06-21-2006
alfredo123 alfredo123 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 44
Thanks vgersh appreciate your help....I also came up with the following during one of my searches

"After the authors got over their initial consternation, they decided to accept the fact, and enhance Awk to make it a better general-purpose programming tool. The new version of Awk was released in 1985. Since the old Awk implementation is still the standard in UN*X systems, the new version is often, if not always, known as Nawk ("New Awk") to distinguish it from the old one."

from http://www.vectorsite.net/tsawk3.html
  #6 (permalink)  
Old 04-18-2007
mike_ap2006 mike_ap2006 is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 12
ignore spaces in search pattern in grep

Hi

can you also tell me how i can acheive the below


i have a code in which i assign a value to a str variable.
Say line contains,
line=Field|Location ES|comp|dur|10

str=`echo $line | awk '{split($0, date,"|"); print date[2]"|"date[3]"|"date[4] }'`

i want to grep for str value in a file in the script.

for j in `cat uniqfile | egrep "${str}"`

but this is giving me the output as
Field|location
ES|comp|dur|10

Whereas i want the output as

Field|Location ES|comp|dur|10


how can i suppress the space here?

could you please help. Thanks, Mike
  #7 (permalink)  
Old 04-18-2007
DeepakS's Avatar
DeepakS DeepakS is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 74
This is because the default input separator is a space. You could get away with reassigning IFS, though I would highly recommend you use a tool like awk to do this.

Code:
line=Field|Location ES|comp|dur|10

str=`echo $line | awk '{split($0, date,"|"); print date[2]"|"date[3]"|"date[4] }'`

export IFS="
"

for j in `cat uniqfile | egrep "${str}"`
do echo $j
done

export IFS=" "

for j in `cat uniqfile | egrep "${str}"`
do echo $j
done

awk ' NF > 0 ' uniqfile

Last edited by DeepakS; 04-18-2007 at 03:37 PM..
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 09:54 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