Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

As above I'm running this grep command which works as it should but how do I store the returned value into a variable?

cat data.txt | grep "" |cut -d\, -f1

I tried this but it didn't work:

rig=$(cat data.txt | grep "" |cut -d\, -f1)
share|improve this question
1  
What is grep "" supposed to do? What is the output of echo $rig? –  Stefan Seidel Sep 14 '12 at 10:00
    
Its ok I'm new to this BASH learning as I go, I believe I need the "" as an argument without it the script wont run? I have found out this works: rig=grep "" data.txt |cut -d\, -f1 and it seems to be storing the value as I expect so this is working for me :) –  twigg Sep 14 '12 at 10:04
    
what is the \ for? –  richard Sep 14 '12 at 10:29
    
you don't need cat or grep. grep "" is pass all, a null pipe, so is cat with 1 argument. –  richard Sep 14 '12 at 10:31
    
No need to escape the comma, either: cut -d, -f1 is sufficient. –  chepner Sep 14 '12 at 13:39

1 Answer 1

  rig=`grep "" data.txt | cut -d\, -f1`

seems to be working for me so I will go with this unless anyone else has any pointers on how to improve the above?

share|improve this answer
    
Did you make a transcription error? This does not work. The one in question does. –  richard Sep 14 '12 at 10:35
2  
I think that's the same as rig=$(cut -d\, -f1 data.txt) without the grep - isn't it? –  RedGrittyBrick Sep 14 '12 at 10:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.