Output file name and file contents of multiple files to a single file

I am trying to consolidate multiple information files (<hostname>.Linux.nfslist) into one file so that I can import it into Excel. I can get the file contents with cat *Linux.nfslist >> nfslist.txt . I need each line prefaced with the hostname. I am unsure how to do this.

--- Post updated at 06:33 PM ---

If I could even just get the filename printed before the contents, that would even be better.

Hello Kentlee65. Try so

cat *Linux.nfslist | sed 's/.*/<hostname>&/' >> nfslist.txt

but sed can read by mask himself

I need it to pull the filename not <hostname>. Here is the output from your command and an example of one of the filename I'm pulling information from.

<hostname>.Linux.nfslist

<hostname>aix_admin_server:/tools/HourlyProcess nfs 25G 10G 16G 40% /tools/HourlyProcess
<hostname>aix_admin_server:/tools/HourlyProcess nfs 25G 10G 16G 40% /tools/HourlyProcess
<hostname>aix_admin_server:/tools/HourlyProcess nfs 25G 10G 16G 40% /tools/HourlyProcess
<hostname>aix_admin_server:/tools/HourlyProcess nfs 25G 10G 16G 40% /tools/HourlyProcess
<hostname>aix_admin_server:/tools/HourlyProcess nfs 25G 10G 16G 40% /tools/HourlyProcess
<hostname>aix_admin_server:/tools/HourlyProcess nfs 25G 10G 16G 40% /tools/HourlyProcess
<hostname>aix_admin_server:/tools/HourlyProcess nfs 25G 10G 16G 40% /tools/HourlyProcess

Try

awk '{print FILENAME, $0}' *Linux.nfslist

and redirect as needed. If you want but the hostname part of the file name, try

awk 'FNR==1 {split (FILENAME, HOST, ".")} {print HOST[1], $0}' *Linux.nfslist
2 Likes

and so

awk 'FNR == 1 {print FILENAME} 1' *Linux.nfslist >> nfslist.txt

RudiC

The first line with an append to my text file worked perfectly. Had to clean up the data with a tr but it imported beautifully.

Thank you

1 Like