Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a file as below:

mime PI Name: ISHO SUCCESS RATE RT, Value: 95.663826
scr  PI Name: RRC Access Failures due to UU, Value: 0.13394141
prog PI Name: RRC Access Failures due to UU, Value: 0.16077702
sch PI Name: RRC Access Failures due to UU, Value: 0.11781933

I want to remove text PI till Value:. I tried

sed '/<PI>/,/<\/Value:>/d' 

Any help?

share|improve this question
add comment

2 Answers

Using the d command in sed will delete the whole line. Also, I'm not sure why you're using < and >. Perhaps you're confusing them with \< and \> that grep uses to denote word boundaries? In that case, you should know that sed uses \b for both types of word boundaries (beginning and ending). So you can write something like this:

sed -i 's/\bPI\b.*\bValue:\b//' your_file

For extra robustness, I would use perl for lazy quantification of . so that you only delete the text between the first occurrence of PI and the first occurrence of Value:. Of course it all depends on your use case.

perl -pi -e 's{ \b PI \b .*? \b Value: \b}{}x' your_file
share|improve this answer
add comment

Replace everything from PI to Value: with empty string:

sed 's/PI.*Value://'
share|improve this answer
add comment

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.