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
insert escape charactor within VIM cin2000 Shell Programming and Scripting 2 03-23-2006 12:46 PM
how to pick out last charactor of a string? cin2000 Shell Programming and Scripting 7 12-22-2005 03:51 PM
Search with awk, but having space within videsh77 Shell Programming and Scripting 1 01-27-2005 12:03 PM
swap space / paging space aaronh AIX 2 05-19-2004 10:06 AM
pageing space vs swap space VeroL UNIX for Dummies Questions & Answers 1 01-22-2004 11:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-30-2008
akmix akmix is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 4
search from specified charactor space

Hello, I'm quite a noobie in programming in UNIX
and I was wondering if it is possible to use 'grep' or similar method
to find PATTERNS from designated location (of charactor)
for example

|param 1 ||param2 |
andrew kim josh
daniel kim michelle
michelle andrew kim

I hope to be able to search up
kim and display only the first 2 lines not the 3rd

i know that cut has -c1-10 so you can specify charactor to cut
but can the grep or other things be done the same? and display the whole line?

thank you very much
regards
  #2 (permalink)  
Old 01-30-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 921
Post

So to clarify, you are wanting to only match lines that have (for example) 'kim' in the first or second field, but display the entire line where it's matched, right?

If so, you'll need a little bit of logic around the grep:
Code:
while read line ; do if echo $line | cut -d ' ' -f 1,2 | grep kim > /dev/null ; then echo $line ; fi ; done
  #3 (permalink)  
Old 01-30-2008
akmix akmix is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 4
Hello Smiling Dragon
Thanks for the post

sorry but what is /dev/null?

and REALLY sorry but i have a small problem
when i do read by line
my ' '(space x 10) is same as ' ' (space x1)
is there a way to keep the spaces as it is while
reading line by line?
thanks (this is important because i cannot use delim as some are like JenniferKim 2 params are stuck together)

Last edited by akmix; 01-30-2008 at 09:07 PM..
  #4 (permalink)  
Old 01-30-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 921
I think I follow what you mean...
If you need something to appear in the forums as you've typed it, surround it with CODE tags (the "#" symbol in the editor).

/dev/null is just a garbage can, it means that I want the output from grep to go nowhere as we don't need it. You can get a similar effect by using grep with the -q option but that only wroks on certain versions of grep.

If your fields are exactly 8 chars wide, we can change the cut call in the code like so:
Code:
cut -d ' ' -f 1,2
Becomes
Code:
cut -c 1-16
(ie, instead of cutting fields 1 and 2 seperated by spaces, we cut chars 1-8 and 9-16)
  #5 (permalink)  
Old 01-30-2008
akmix akmix is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 4
oh, thank you
well my code is exactly certain character wide but
when i use read line by line method
it seems to shrink it down
so if i type

cat emplist
Andrew Kim..........Daniel Kim
Henry Kim..........Danny Kim
Daniel Taegyun tk KimAndrew Kim

but read line then echo'ing it gives me
Andrew Kim.Daniel Kim
Henry Kim.Danny Kim
Daniel Taegyun tk KimAndrew Kim

is there -(something) statement that preserves the # #?
sorry my question is starting to go really long..
and I've replaced (space) with . thanks

ps. i'v tried # #? and # # is same as # #?

regards
  #6 (permalink)  
Old 01-30-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 921
If we're talking about formatting problems, you must use CODE tags or we'll never understand what you are after.
However, If you want echo to not contract spaces, add quotes around the params passed to it:
Code:
then echo $line
Becomes
Code:
then echo "$line"
  #7 (permalink)  
Old 01-30-2008
akmix akmix is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 4
thank you for your fast reply
I think i've got it working
Sponsored Links
Closed Thread

Bookmarks

Tags
grep or

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 02:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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