Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am working with the egrep command and I need to pair with the cut (and ONLY cut) command to change a ":" into a tab. For example change:

Blahblahblah:2000

to:

Blahblahblah    2000

I currently have this, but it turns the ":" into "/t" and not tab:

egrep -e "^[0-9]" *.txt | cut -d ":" --output-delimiter="/t" -f 1- > test.txt
share|improve this question

2 Answers 2

up vote 3 down vote accepted

Use this:

egrep -e "^[0-9]" *.txt | cut -d ":" --output-delimiter=$'\t' -f 1- > test.txt

should work in Bash.

share|improve this answer
    
Perfect! Thank you. I checked the man page for cut and I didn't see anywhere that explained what "$" does. Could you please explain that bit to me? –  gbrooks Feb 12 at 9:21
    
@gbrooks: It's not actually 'cut', it's Bash. Bash expands the backslash escapes in strings like $'..' and only strings like that. '\t' is standard escape for a tab. –  minerz029 Feb 12 at 9:22
    
Ah ok, thank you. I just ran the command noticed I got twice as many lines as I should have (as noted by the assignment this is for). Without going too much off topic, does the fact that it uses Bash cause this? –  gbrooks Feb 12 at 9:24
    
@gbrooks: Shouldn't cause any problems using Bash. You may ask a new question, however. –  minerz029 Feb 12 at 9:25
    
Alright. Thank you so much for your help. –  gbrooks Feb 12 at 9:25

Alternately, you can also use the tr command, if your need is to just replace the delimiter as follows

echo "Blahblahblah:2000" | tr ':' '\t'

You will get the following output

Blahblahblah    2000
share|improve this answer
1  
From the question: "... cut (and ONLY cut) command ..." –  muru 2 days ago

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.