The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search for string dublicates in column lulle Shell Programming and Scripting 7 02-19-2008 04:32 PM
String search and return value from column jaydeep_sadaria Shell Programming and Scripting 3 01-12-2008 04:31 AM
column based search user_007 Shell Programming and Scripting 8 07-01-2007 06:52 AM
Select records based on search criteria on first column shashi_kiran_v UNIX for Dummies Questions & Answers 2 12-02-2005 01:49 PM
Search for by column and delete line thudak Shell Programming and Scripting 4 04-24-2002 10:13 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 09-18-2008
Korn0474 Korn0474 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
Can SED Search By Column?

Hi all,

I am trying to search for a keyword in the fourth column of a massive carrot(^) delimited file and unfortunately I cannot use AWK (which would have been ideal). Can SED (or maybe even GREP) perform a search like this?
  #2 (permalink)  
Old 09-18-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,417
are you ready to go with the combination of cut and sed command??
  #3 (permalink)  
Old 09-18-2008
Korn0474 Korn0474 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
Quote:
Originally Posted by vidyadhar85 View Post
are you ready to go with the combination of cut and sed command??
I'm open to any suggestions at this point
  #4 (permalink)  
Old 09-18-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,417
then this will do..
Quote:
cut -f4 -d \^ filename | sed 's/searchpattern/replacepattern/g'
  #5 (permalink)  
Old 09-18-2008
Korn0474 Korn0474 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
Quote:
Originally Posted by vidyadhar85 View Post
then this will do..
Quote:
cut -f4 -d \^ filename | sed 's/searchpattern/replacepattern/g'
Thanks, but there is no replacement pattern in my case. I just need it to return the complete line that matches the search pattern to me. I tried modifying your example by omitting the "replacepattern" argument but that gave me an error that said it couldn't be parsed.
  #6 (permalink)  
Old 09-18-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,417
for that use this..
Quote:
cut -f4 -d \^ filename | sed -ne '/searchpattern/p'
  #7 (permalink)  
Old 09-18-2008
Korn0474 Korn0474 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
Quote:
Originally Posted by vidyadhar85 View Post
for that use this..
Quote:
cut -f4 -d \^ filename | sed -ne '/searchpattern/p'
Thanks for working with me on this problem. I need to ask your help with one more correction. This command you suggested outputs only the search pattern when found. How can I make it output the entire line where the search pattern was found?

Example: If I'm searching for "SMITH" then cut -f4 -d \^ filename | sed -ne '/SMITH/p' returns:
SMITH
SMITH


I need it to return:
data1^adbde^1981^SMITH
ender2^23232^1972^SMITH
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 01:31 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