LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find exact string (https://www.linuxquestions.org/questions/linux-newbie-8/find-exact-string-668835/)

Swapna173 09-10-2008 01:20 AM

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

chrism01 09-10-2008 02:27 AM

grep '^Price,' file.csv|cut -d',' -f2

Swapna173 09-10-2008 03:01 AM

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.

chrism01 09-10-2008 03:52 AM

Actually, you missed the fact I included the comma at the end of the match string to avoid that problem
;)

Swapna173 09-11-2008 11:25 PM

Quote:

Originally Posted by chrism01 (Post 3275543)
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.


All times are GMT -5. The time now is 08:12 PM.