Find exact string | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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

Find exact string

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-09-2008
Swapna173 Swapna173 is offline
Registered User
 
Join Date: May 2008
Last Activity: 1 February 2010, 3:46 AM EST
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Find exact string

Hi Guys,

File is containing data
Col1 Col2
ListPrice List Price
Price Average Selling Price - Actual
ProjPrice Average Selling Price
ProjPrice Launch Price
ProjCost Cost

Now i need to print col2 on the basis of col1
i.e if i Pass Price it should display only "Average Selling Price - Actual"

I tried using grep which print first 4 lines like.
cat StrykerData_Cubes.csv |grep "Price" | cut -d "," -f2 | tr -s " " "_"

even sed command like
cat StrykerData_Cubes.csv |grep -w "Price" | sed /^Price/p
Sponsored Links
    #2  
Old 09-09-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 9 April 2014, 1:31 AM EDT
Location: INDIA, Bangalore
Posts: 2,049
Thanks: 16
Thanked 107 Times in 103 Posts
sed -ne '/^Price/p' filename | sed -e 's/^ *[^ ]* //'
try this.. and don't use cat when you are using command like grep,awk and sed
Sponsored Links
    #3  
Old 09-09-2008
Swapna173 Swapna173 is offline
Registered User
 
Join Date: May 2008
Last Activity: 1 February 2010, 3:46 AM EST
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
this does not work if i use it in the for Loop. In fact it search the string in the beginning and there are lines where the beginning string matches. there this one does not work.

Last edited by Swapna173; 09-09-2008 at 10:09 AM..
    #4  
Old 09-09-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 9 April 2014, 1:31 AM EDT
Location: INDIA, Bangalore
Posts: 2,049
Thanks: 16
Thanked 107 Times in 103 Posts
var=search string
nawk -v v=var 'if($1==$v)
{$1="";$0=substr($0,2)}1'
try something like this not sure because not tested :-)
Sponsored Links
    #5  
Old 09-09-2008
dennis.jacob's Avatar
dennis.jacob dennis.jacob is offline Forum Advisor  
Registered User
 
Join Date: Feb 2007
Last Activity: 30 March 2014, 9:33 AM EDT
Location: Singapore/Cochin
Posts: 871
Thanks: 0
Thanked 12 Times in 11 Posts
Try :


Code:
var=Price
awk '/^'$var'/{ $1=""; print; }' < StrykerData_Cubes.csv

Output:

Quote:
/home/ans >awk '/^'$var'/{ $1=""; print; }' < StrykerData_Cubes.csv
Average Selling Price - Actual
Sponsored Links
    #6  
Old 09-10-2008
Swapna173 Swapna173 is offline
Registered User
 
Join Date: May 2008
Last Activity: 1 February 2010, 3:46 AM EST
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Exact match

Sorry i made a mistake mine is a comma separated file, so i need to print col2 corresponding to search in col1. and will this one match the exact string means not the substring of a string
Sponsored Links
    #7  
Old 09-10-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Advisor  
The Tutor
 
Join Date: Jun 2008
Last Activity: 9 April 2014, 1:31 AM EDT
Location: INDIA, Bangalore
Posts: 2,049
Thanks: 16
Thanked 107 Times in 103 Posts
Quote:
Originally Posted by Swapna173 View Post
Sorry i made a mistake mine is a comma separated file, so i need to print col2 corresponding to search in col1. and will this one match the exact string means not the substring of a string
then it made your work more easy..
awk -F"," then compare $1 with your required value and print $2
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed thibodc Shell Programming and Scripting 1 05-23-2012 11:14 PM
Sed find exact string and delete line with variable markdjones82 Shell Programming and Scripting 1 04-24-2012 03:30 PM
foreach with exact string moyzZ UNIX for Dummies Questions & Answers 2 03-08-2011 04:26 AM
what is the find command to find exact dir from the root rajkumar_g Shell Programming and Scripting 1 11-22-2010 08:49 AM
Find an exact string gr8pals Solaris 2 07-15-2008 06:17 AM



All times are GMT -4. The time now is 12:11 PM.