I want to list files that do not start with a certain string

May 16, 2012 at 03:44:49
Specs: Linux x86_64
I want to list files that do not start with a certain string

See More: I want to list files that do not start with a certain string

Report •

#1
May 16, 2012 at 08:30:02
For each file in your current directory, this awk script looks at only line 1 and skips printing each file that does not start with the string: certain string:

#!/bin/bash

#cd <to your directory>
awk ' {
   if(FNR == 1)
      if($0 ~ /^certain string/)
         x=1
      else
         print FILENAME
}
' *


Report •

#2
May 16, 2012 at 11:15:38
ls | grep -ve '^certain string'

Report •

#3
May 16, 2012 at 11:34:22
Paul:

The problem with grep in this case is that displays ANY line not starting with 'certain string' (and thus any file name) which is not what was asked for.


Report •

Related Solutions

#4
May 16, 2012 at 16:20:34
Nails

read original post again.

I want to list files that do not start with a certain string

If you want to see all files containing "certain string", you simply must not use the option -v and looks like this:
ls | grep -e '^certain string'


Report •

Ask Question