The UNIX and Linux Forums  

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
Find number of columns in a file rahul26 UNIX for Dummies Questions & Answers 13 05-08-2009 06:11 AM
awk / grep / Prints all columns except the first one knijjar Shell Programming and Scripting 17 02-29-2008 05:14 AM
How to grep a number in a file name ahjiefreak Shell Programming and Scripting 3 12-11-2007 04:56 AM
Grep a number from a line in ksh rodluo Shell Programming and Scripting 3 12-09-2007 09:31 AM
Finding number ranges using grep DKNUCKLES Shell Programming and Scripting 2 11-07-2007 02:30 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 Rate Thread Display Modes
  #1 (permalink)  
Old 02-12-2008
MaestroRage MaestroRage is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 20
using Grep for only a certain number of columns

I am given a file with a list of names for the first 20 characters. The 20 characters after is a list of names that somebody is supposed to team up with.

Now i'm trying to write a simple script that will read a name somebody inputs and then looks only in the first 20 characters.

For example. (Due to the nature of BBS posting length of columns are not given, the first name is the desired target for searching, the second name is the person teamed up with the first.

John Bow : Lucy Hemmings
Bob Billy : Bibliotheque Frenchness
Lucy Hemmings : John Bow

if somebody inputs John, I would get both Lucy and John, and this is not what I want. Any ideas?

I am considering piping grep -w with something else as it seems to at least cut out all the names which have no relevance.
  #2 (permalink)  
Old 02-12-2008
HPAVC's Avatar
HPAVC HPAVC is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 106
Quote:
Originally Posted by MaestroRage View Post
I am considering piping grep -w with something else as it seems to at least cut out all the names which have no relevance.
The extra whitespace in that sample is sort of hard to write something exacting. But yeah grep and pipe are the solutions imo.

grep -i -E "^$NAME " $FILE | cut -f2 -d:
  #3 (permalink)  
Old 02-13-2008
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172

Code:
in_file=/path/to/file
read input
awk -v name=$input -F: 'tolower($1) ~ name { print $2 }' $in_file

Is this what you're looking for ?
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 10:49 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