w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
grep for files containin specific text in a specific line at a specific position

How about using head to get the first line of each file, then grep with a corresponding regexp and output the line before to retain the filename:

head -n1 * | grep -EB1 '^.{6}OB'

Of course, you have to change the file selection - here *- to suit your needs.

Update: Question was updated - If you just want the filenames, just add another grep to catch the filenames given by the head command:

head -n1 * | grep -EB1 '^.{6}OB' | grep '==>'

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.