LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-10-2008, 01:20 AM   #1
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Rep: Reputation: 15
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
PriceFact,Cost-Actual

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
Edit/Delete Message
 
Old 09-10-2008, 02:27 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
grep '^Price,' file.csv|cut -d',' -f2
 
Old 09-10-2008, 03:01 AM   #3
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Original Poster
Rep: Reputation: 15
This command will search the beginning of the string so if file is
Col1 Col2
ListPrice,List Price
Price,Average Selling Price - Actual
ProjPrice,Average Selling Price
ProjPrice,Launch Price
ProjCost,Cost
ProjCostAct,Cost-Actual

For the col1 value as ProjCost if returns last 2 rows whereas it should display only the 5th row.
 
Old 09-10-2008, 03:52 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Actually, you missed the fact I included the comma at the end of the match string to avoid that problem
 
Old 09-11-2008, 11:25 PM   #5
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
Actually, you missed the fact I included the comma at the end of the match string to avoid that problem

Hey thanks. I understood line. and this solved my problem.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep question - match exact string Panagiotis_IOA Linux - General 2 01-20-2014 04:34 AM
grep the exact string only ZAMO Linux - General 11 08-28-2008 05:08 AM
find exact phrase subnet_rx Linux - General 1 03-29-2008 08:28 PM
Find/locate an exact file stefaandk Linux - General 2 12-27-2005 07:56 AM
how to find an exact substring match? ldp Programming 7 02-22-2005 06:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration