matching pattern to end of line

I have the following code and want to get only the comments.

Ideally I would like to replace the characters to the left of the first '!' in the line with blanks.

 
  real, dimension(:), allocatable :: ft  ! stores a single trace
  real, dimension(:), allocatable :: tr  ! stores a single trace (extended to size of ft)
                                                            
  nt = size(tcube,1)
  nx = size(tcube,2)
  ny = size(tcube,3)
  nf = size(fcube,1)

  ! trace in the frequency domain
  allocate( ft(nf) )

  ! trace extended to size(ft)
  allocate( tr(nf) )

Output would be as follows.

 
                                         ! stores a single trace
                                         ! stores a single trace (extended to size of ft)
  ! trace in the frequency domain
  ! trace extended to size(ft)

Before we start finding you a solution, would you mind providing a sample of the desired output file?

Hi

grep '!' infile | sed 's/.*!/!/'

Tried

  grep "!" radon3d_subs.f90 | sed 's/.*!//'

but am getting

//: Event not found.
awk '/!/{gsub(/./," ",$1); print }' OFS=! FS=! infile

Got an error using the following

grep '!' radon3d_subs.f90 | sed 's/.*!/!/'
/!/: Event not found.

---------- Post updated at 05:34 AM ---------- Previous update was at 05:32 AM ----------

The command gives an error

awk '/{gsub(/./," ",$1); print }' OFS=! FS=! radon3d_subs.f90
awk: fatal: Unmatched ( or \(: /{gsub(/

---------- Post updated at 05:39 AM ---------- Previous update was at 05:34 AM ----------

Seems that the 'Event not found' error is from the csh shell. Unfortunately on this machine I have to use csh, so I escape the !.

Is not what I have posted. You must filter the output with /!/

 awk '/!/{gsub(/./," ",$1); print }' OFS=! FS=! radon3d_subs.f90
/: Event not found.

The problem was that when I captured the command in the history it chucked that thing out. Another reason against csh!!!

---------- Post updated at 06:04 AM ---------- Previous update was at 05:49 AM ----------

I have tried

grep "!" radon3d_subs.f90 | sed 's/.*\! //'

on the following

  !!
  !! SUB radon3d_temporal_fourier

  subroutine radon3d_temporal_fourier( tcube, fcube, c_dir )
  implicit none

  ! Arguments

  real, dimension(:,:,:), intent(in) :: tcube
  complex, dimension(:,:,:), intent(in) :: fcube
  character(len=*), intent(in) :: c_dir

  ! Local variables

  real, dimension(:), allocatable :: ft  ! stores a single trace
  real, dimension(:), allocatable :: tr  ! stores a single trace (extended to size of ft)

  ! IMPLEMENTATION ---------------------------------------------------------------------------------

  nt = size(tcube,1)
  nx = size(tcube,2)
  ny = size(tcube,3)
  nf = size(fcube,1)

  ! trace in the frequency domain
  allocate( ft(nf) )

  ! trace extended to size(ft)
  allocate( tr(nf) )

  !!> SELECT TRANSFORMATION DIRECTION

  select case ( c_dir(1:1) )

    !!> time to frequency
    case ('+')

      do iy = 1, ny

          do ix = 1, nx
              tr(nf) = 0.0  !!> ensures last sample is zero when nf > nt
              tr(1:nt) = (tcube(1:nt,ix,iy)
              ft = cfft(tr, '+')
              fcube(1:nf,ix,iy) = ft(1:nf)
          enddo

      enddo

    !!> frequency to time
    case ('-')

      do  iy = 1, ny

          do  ix = 1, nx
              ft(1:nf) = fcube(1:nf,ix,iy)
              tr = cfft(ft, '-')
              tcube(1:nt,ix,iy) = tr(1:nt)  !!> nt may be smaller than nt
          enddo

      enddo

    case default

      ! do nothing

  end select

and I am getting

SUB radon3d_temporal_fourier
Arguments
Local variables
stores a single trace
stores a single trace (extended to size of ft)
IMPLEMENTATION ---------------------------------------------------------------------------------
trace in the frequency domain
trace extended to size(ft)
  !!> SELECT TRANSFORMATION DIRECTION
    !!> time to frequency
              tr(nf) = 0.0  !!> ensures last sample is zero when nf > nt
    !!> frequency to time
              tcube(1:nt,ix,iy) = tr(1:nt)  !!> nt may be smaller than nt
do nothing

Almost correct. There is a problem that the match in sed

grep "!" radon3d_subs.f90 | sed 's/.*\! //'

removes the '!'

---------- Post updated at 06:44 AM ---------- Previous update was at 06:04 AM ----------

I tried the following

  !!
  !! SUB radon3d_temporal_fourier
  ! Arguments
  ! Local variables
  real, dimension(:), allocatable :: ft  ! stores a single trace
  real, dimension(:), allocatable :: tr  ! stores a single trace (extended to size of ft)
  ! trace in the frequency domain
  ! trace extended to size(ft)
  !!> SELECT TRANSFORMATION DIRECTION
    !!> time to frequency
              tr(nf) = 0.0  !!> ensures last sample is zero when nf > nt
    !!> frequency to time
              tcube(1:nt,ix,iy) = tr(1:nt)  !!> nt may be smaller than nt
      ! do nothing
grep "!" radon3d_subs.f90 | sed 's/(.*)(!.*)/\2/'

This produces the following. As you can see when I have '!!', these are changed to
a single '!'. How can I modify this so I get '!!'?

! SUB radon3d_temporal_fourier
! Arguments
! Local variables
! stores a single trace
! stores a single trace (extended to size of ft)
! trace in the frequency domain
! trace extended to size(ft)
!> SELECT TRANSFORMATION DIRECTION
!> time to frequency
!> ensures last sample is zero when nf > nt
!> frequency to time
!> nt may be smaller than nt
! do nothing

Hi
csh so use this :

perl -ne 's/.*?\!/\!/; print if /\!/;' radon3d_subs.f90