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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print file name and then its contets 1

Status
Not open for further replies.

babcia01

IS-IT--Management
Jul 11, 2002
37
0
0
US
I have x number of files in the same dir which are named x.jun.2009.

So far, my awk statements does now work.

Question:
Looping thru all file names, I want to print the file name and then print its contents ,the print another file name , its contents until no more files found.
Thank you in advance
 
Hi

babcia01 said:
So far, my awk statements does now work.
So far we saw nothing from your problem.
[ul]
[li]Post your current code.[/li]
[li]Tell us where it fails.[/li]
[/ul]
By the way, I would say this is not a typical [tt]awk[/tt] task, as there is no record/field based data manipulation, in which [tt]awk[/tt] excels. So I would do it with a shell script.

Feherke.
 
ls -l *jun.2009|awk '{print $9}'|xargs -n1 cat


The above prints contents of each file. I want file name before content is printed
 
Hi

Why [tt]ls -l[/tt] ? You are not using any other file attribute, just name. So why asking for the file attributes ?
Code:
ls -[purple]1[/purple] [teal]*[/teal]jun[teal].[/teal][purple]2009[/purple] [teal]|[/teal] [b]while[/b] [COLOR=chocolate]read[/color] name[teal];[/teal] [b]do[/b] echo [green][i]"$name"[/i][/green][teal];[/teal] cat [green][i]"$name"[/i][/green][teal];[/teal] [b]done[/b]

[gray]# or[/gray]

[b]for[/b] name [b]in[/b] [teal]*[/teal]jun[teal].[/teal][purple]2009[/purple][teal];[/teal] [b]do[/b] echo [green][i]"$name"[/i][/green][teal];[/teal] cat [green][i]"$name"[/i][/green][teal];[/teal] [b]done[/b]
But this is off-topic.


Feherke.
 
As we are in the awk forum:
Code:
awk 'FNR==1{print FILENAME}1' *jun.2009

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top