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
text manipulation injeti Shell Programming and Scripting 11 06-05-2008 10:42 AM
file manipulation tungaw2004 Shell Programming and Scripting 2 04-04-2008 10:26 PM
Text Manipulation. Icepick Shell Programming and Scripting 4 02-25-2008 04:18 AM
Text file manipulation svannala UNIX for Dummies Questions & Answers 5 01-20-2006 07:01 PM
shell script : text manipulation (easy quesiton) champion Shell Programming and Scripting 3 07-01-2002 03:10 AM

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 02-25-2008
Ezy Ezy is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 5
Post Text file manipulation

I am a new unix user & I wanted to work with unix as it is very good in text manipulations. I need a little help. I will be grateful if someone can help me out.

I need help in grepping a pattern of numbers from one file to another file. Specific details are as follows:

File one contains only one column of numbers like

897887738753
881388745527
237818494899
331388745702
451388746000
911388746146
891388746156

file 2 contains three column of numbers 1st column is just the hash mark then another set of numbers & then column 3 (the numbers of my interest).

## 234451388746000 447887738753
## 234159018106564 447818494899
## 234159055332992 897887738753
## 234159043784408 881388745527
## 234159026266547 237818494899
## 234154821274370 331388745702
## 234159053081262 451388746000
## 234159020233321 911388746146
## 234159014081879 891388746156

I want to grep numbers in File 1 from 3rd column of file 2 and as a result I should get out put as the whole line in file 2 which has the matching number in column 3 of file 1

I am trying: grep -f file1 file2 > file3

but the problem with it is that if it finds a similar match even in column 2 it prints it. Like in above case output will be

## 234159055332992 897887738753
## 234159043784408 881388745527
## 234159026266547 237818494899
## 234154821274370 331388745702
## 234159053081262 451388746000
## 234159020233321 911388746146
## 234159014081879 891388746156

&

## 234451388746000 447887738753 (which is not right because the 3rd column of file2 does not have any match in file1)


One more thing I am using cygwin to create unix enviornment on my windows machine & its not actually a unix machine but just unix environment.
  #2 (permalink)  
Old 02-25-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
Code:
nawk 'NR==FNR{x[$1];next}$3 in x'  file1 file2
  #3 (permalink)  
Old 02-25-2008
Ezy Ezy is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 5
Post Giving the same out put as I was getting from grep -f

Hi I tried the above but I am getting the same out put as I was getting with grep -f
  #4 (permalink)  
Old 02-25-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
strange - looks fine to me:

Code:
#  cat file1
897887738753
881388745527
237818494899
331388745702
451388746000
911388746146
891388746156


#  cat file2
## 234451388746000 447887738753
## 234159018106564 447818494899
## 234159055332992 897887738753
## 234159043784408 881388745527
## 234159026266547 237818494899
## 234154821274370 331388745702
## 234159053081262 451388746000
## 234159020233321 911388746146
## 234159014081879 891388746156


#  nawk 'NR==FNR{x[$1];next}$3 in x'  file1 file2
## 234159055332992 897887738753
## 234159043784408 881388745527
## 234159026266547 237818494899
## 234154821274370 331388745702
## 234159053081262 451388746000
## 234159020233321 911388746146
## 234159014081879 891388746156


#  nawk 'NR==FNR{x[$1];next}$3 in x'  file1 file2 | wc 
       7      21     225

#  /usr/xpg4/bin/grep -f file1 file2 | wc 
       8      24     257
do you want to post you exact command sequence /output ?
  #5 (permalink)  
Old 02-25-2008
Ezy Ezy is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 5
Post Thanks its working

Thanks a lot its working..I am grateful.
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 06:34 AM.


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