Take the 2-minute tour ×
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 script that uses diff -c then puts the output on a text file. What I want is to remove the line that does not have the "!" and display the lines with the exclamation mark. Is this possible? Can the cut command do the trick?

I wanted to use diff -c because it separates the files from directory1 to directory2.

example:

*** 1,3 ****
! 3856715355 /home/dir
  4294967277 /home/dir/file1 <---remove this line
! 154272340 /home/dir/file5
--- 1,4 ----
! 1765342654 /home/dir
  4294967277 /home/dir/file1 <--- remove this line
! 803775803 /home/dir/file4
! 2580902204 /home/dir/file99
share|improve this question
    
awk '/^!/' <filler> –  HalosGhost Jan 12 at 19:01

2 Answers 2

up vote 1 down vote accepted
  • with grep:

    diff -c file1 file2 | grep '^[-!*]'`
    
  • with sed:

    diff -c file1 file2 | sed '/^[-!*]/!d'
    
share|improve this answer
    
but then it also removes the separation from dir1 to dir2 –  midnight27 Jan 12 at 18:49
    
@midnight27 ... but then you need to put more input in your question. –  peterph Jan 12 at 18:53
    
@midnight27 see the update –  jimmij Jan 12 at 18:54

With grep:

diff -c file1 file2 | grep -v '^  '

none of the other lines start with two spaces: not the ones starting with !, and not the line indications.

share|improve this answer

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.