The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


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 !!


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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-30-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 565
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
  #3 (permalink)  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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 05:07 PM.
Reply With Quote
  #4 (permalink)  
Old 01-30-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 565
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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)
Reply With Quote
  #5 (permalink)  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB 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 -7. The time now is 05:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102