Is there any way to cat multiple files and show filenames?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Is there any way to cat multiple files and show filenames?
# 1  
Old 12-18-2014
Is there any way to cat multiple files and show filenames?

Hi,

Is there any way to do a cat * where it shows the name of each file in the process? Similar to what more does below?



Code:
$ more ?.sql
::::::::::::::
1.sql
::::::::::::::
set linesize 200
select db_unique_name,
       cast(
              from_tz(
                      cast( oldest_flashback_time as timestamp )
                     ,dbtimezone )
              at time zone 'Pacific/Melbourne' as date ) oldest_db_fb
       , round((sysdate - oldest_flashback_time) * 24, 1) oldest_db_fb_hours
       , d.inst_id
from   gv$flashback_database_log l, gv$database d
where  l.inst_id = d.inst_id
order by d.inst_id
;
::::::::::::::
2.sql
::::::::::::::
set linesize 200
alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'
;

col name format a60
col db_unique_name format a15
select a.db_unique_name, b.name, a.first_time_min, a.inst_id, a.database_role, sysdate
from ( select db_unique_name, min(first_time) first_time_min, max(first_time) first_time_max, d.name, f.inst_id, d.database_role, sysdate
       from   gv$flashback_database_logfile f, gv$database d
       where  f.inst_id = d.inst_id
       group by db_unique_name, d.name, f.inst_id, d.database_role
       order by f.inst_id ) a,
     gv$flashback_database_logfile b
where b.first_time = a.first_time_min and
      b.inst_id = a.inst_id
;

select a.db_unique_name, c.name, a.first_time_max, a.inst_id, a.database_role, sysdate
from ( select db_unique_name, min(first_time) first_time_min, max(first_time) first_time_max, d.name, f.inst_id, d.database_role, sysdate
       from   gv$flashback_database_logfile f, gv$database d
       where  f.inst_id = d.inst_id
       group by db_unique_name, d.name, f.inst_id, d.database_role
       order by f.inst_id ) a,
     gv$flashback_database_logfile c
where c.first_time = a.first_time_max and
      c.inst_id = a.inst_id
;

::::::::::::::
3.sql
::::::::::::::
set linesize 200
alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'
;

col name format a20
select db_unique_name, min(first_time), max(first_time), d.name, f.inst_id, d.database_role, sysdate
from   gv$flashback_database_logfile f, gv$database d
where  f.inst_id = d.inst_id
group by db_unique_name, d.name, f.inst_id, d.database_role
order by f.inst_id
;

# 2  
Old 12-18-2014
I think simplest way to do it is using more and pipe.

Code:
more * | cat

or tail command

Code:
tail -n +1 file1 file2

# 3  
Old 12-18-2014
You can define a shell function like
Code:
cf () 
{ 
    for x in $@;
    do
        echo $x:;
        cat "$x";
    done;
    unset x
}

This is quite simple a definition, no error checking is done, nor precautions against e.g. exceeding LINE_MAX taken.

Last edited by RudiC; 12-18-2014 at 06:38 AM..
# 4  
Old 12-18-2014
How about awk internal FILENAME variable :
Code:
awk ' { print FILENAME $0 } ' *

# 5  
Old 12-18-2014
Or
Code:
grep ^ /dev/null *

# 6  
Old 12-18-2014
That's clever. The /dev/null forces it to be more than one filename, so names aren't omitted.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Show only the filenames under a directory without relative and absolute paths.

I am able to list all the filenames under a directory & its sub-directories except blent.tar on Linux find "/tmp/" -type f | grep -v blent.tar | rev | cut -d '/' -f1 | rev Desired Output: THIRDPARTYLICENSEREADME.txt javaws libjavaplugin_oji.so libjavaplugin_oji.so... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

There are multiple filenames in the directory.How to return the the lastest files for each file name

there are mutiple file nams in the directory. How to return the the lastest files for each file name. ex. abc1234_050201 abc1234_050206 abc1234_050208 xyz34_050204 xyz34_050210 xyz34_050218 thanks (4 Replies)
Discussion started by: grand_sam
4 Replies

3. UNIX for Dummies Questions & Answers

CAT multiple files according to file name

I have a folder that contains a number of files with file names as follows: XX.YYYY..ZZZ.2014.001.000000 XX.YYYY..ZZZ.2014.001.000400 XX.YYYY..ZZZ.2014.001.000800 XX.YYYY..ZZZ.2014.001.001200 XX.YYYY..ZZZ.2014.001.001600 ..... XX.YYYY..ZZZ.2014.002.000000 XX.YYYY..ZZZ.2014.002.000400... (8 Replies)
Discussion started by: quakesrus
8 Replies

4. UNIX Desktop Questions & Answers

trying to cat multiple pairs of files

I have a number of files in a directory named like this: fooP1, fooN1, fooP2, fooN2 ... fooP(i), fooN(i). I'd like to know how to combine each P and N pair into a single file, foo(i) TIA John Balwit (1 Reply)
Discussion started by: balwit
1 Replies

5. Shell Programming and Scripting

bash: cat multiple files together except first line?

Hopefully the title summarized what I need help with. I have multiple files that I would like to concatenate in bash. ie: cat file1 file2 file3 > bigfile except I do not want to include the first line from each file (). Any help? Thanks. (6 Replies)
Discussion started by: sanimfj
6 Replies

6. UNIX for Dummies Questions & Answers

cat multiple files questions

Hi-- I'm trying to figure out how to use cat more wisely. I have the following command, which works, but I'd like to understand how to get it to work more clearly and efficiently. cat 'my file.001' 'my file.002' 'my file.003' 'my file.004' 'my file.005' 'my file.006' 'my file.007' 'my... (6 Replies)
Discussion started by: rlinsurf
6 Replies

7. Shell Programming and Scripting

extract multiple cloumns from multiple files; skip rows and include filenames; awk

Hello, I am trying to write a bash shell script that does the following: 1.Finds all *.txt files within my directory of interest 2. reads each of the files (25 files) one by one (tab-delimited format and have the same data format) 3. skips the first 10 rows of the file 4. extracts and... (4 Replies)
Discussion started by: manishabh
4 Replies

8. Shell Programming and Scripting

read list of filenames from text file and remove these files in multiple directories

I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)
Discussion started by: fxvisions
5 Replies

9. UNIX for Dummies Questions & Answers

How can I rename multiple files depending on a string occuring in the filenames?

I have many files that have "inputstring" somewhere in their filename (without the quotes), and I want to rename them all so that "inputstring" is replaced with "newstring". And I also want to specify arbitrary text for "inputstring" and "newstring" so that I can call the scripts that does this... (6 Replies)
Discussion started by: karman
6 Replies

10. Shell Programming and Scripting

Script to backup multiple files and amend their filenames

Hi, I'm trying to write a command that backs up certain files into my current directory and adds a prefix to the backed up file name. I realise this can be done in a script by specifying each individual file but would like to know if it can be done on one line and made an alias. I have the... (5 Replies)
Discussion started by: m223464
5 Replies
Login or Register to Ask a Question