Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print filename and 1st line of every file within a directory 1

Status
Not open for further replies.

bassfass

IS-IT--Management
May 22, 2003
5
US
I'm sure I saw this as an example somewhere. Creating a new file that contains a file list & 1st line of current directory ie.:
File1.dat This is the first line of 1st file
File2.dat This is the first line of 2nd file

etc. for as many files as in the directory.
Anybody got a quickie?
 
Something like
Code:
for i in *.dat;
do
  echo -n $i
  head -1 $i
  ## awk 'FNR==1 { print }' $i  ## if you want an awk answer
done
 
awk 'FNR==1 {print FILENAME, $0}' *.dat > report.txt
 
Perfect.
Thanks so much. You guys are the greatest
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top