Print File name along with file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Print File name along with file
# 1  
Old 06-22-2007
Question Print File name along with file

I have around 50 text files containing raw data and i need to print them for further analysis. The problem I am facing is that, the files themselves do not have any identifying headers and as without the file names, the data is useless to me. My question is, is there a way to print the file's content and the file name (if possible, the path also) as the header/footer of the file.

I attempted to use the lpr but it didn't workout - probably due to my complete incompetence when it comes working with printer Smilie
Otherwise, my only alternative will be to print each file and manually write the file name..............
# 2  
Old 06-22-2007
Hi.

One utility you can use is pr. For example, I have a file s2, and when I use pr s2, the header contains:
Code:
2007-06-18 14:57                        s2                        Page 1

To add the complete path, you can use pr $PWD/s2 to get:
Code:
2007-06-18 14:57            /home/drl/try/sam/s2                  Page 1

Note that pr will paginate your entire file, adding the title on each "page" -- see man pr for details and options... cheers, drl
# 3  
Old 06-22-2007
Code:
(echo $PWD/your_file; cat your_file) | lpr

# 4  
Old 06-22-2007
Hi.
Quote:
Originally Posted by Shell_Life
Code:
(echo $PWD/your_file; cat your_file) | lpr

I like that solution; I would add another echo:
Code:
(echo $PWD/your_file; echo; cat your_file) | lpr

for visual separation.

However, for many files, one would probably want to place this in a loop -- no one wants to do this 50 times manually. A script would be suitable, if one knows how to do that.

On the other hand, if one does not mind the pagination from pr, then:
Code:
pr $PWD/* | lpr

seems like a compact solution that processes all the files, the text for new files appearing at the top of a new page of paper, etc. In place of the *, other filename expressions could be used, e.g. a1[0-8] for a10, a11, ... a18, for subsets of filenames.

That's one of the useful characteristics of *nix, there is more than one approach to solving a problem ... cheers, drl
# 5  
Old 06-22-2007
guys.....thanks for the quick suggestion............it worked like a dream.......just need to analyze all thoes stupid data.............
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

2. Shell Programming and Scripting

Find columns in a file based on header and print to new file

Hello, I have to fish out some specific columns from a file based on the header value. I have the list of columns I need in a different file. I thought I could read in the list of headers I need, # file with header names of required columns in required order headers_file=$2 # read contents... (11 Replies)
Discussion started by: LMHmedchem
11 Replies

3. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

4. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

5. Shell Programming and Scripting

Search row by row from one file to another file if match is found print few colums of file 2

this is the requirement list.txt table1 table2 table3 testfile.txt name#place#data#select * from table1 name2#place2#data2#select * from table 10 innerjoin table3 name2#place2#data2#select * from table 10 output name place table1 name2 place table3 i tried using awk (7 Replies)
Discussion started by: vamsekumar
7 Replies

6. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

7. UNIX for Dummies Questions & Answers

find locked files, print file path, unlock file

using OS X and the Terminal, I'd like to find all locked files in a specified directory, unlock them, and print a list of those files that were unlocked how can I do this? I'm familiar with chflags nouchg for unlocking one file but not familiar with unix enough to do what I'd like. Thanks! (0 Replies)
Discussion started by: alternapop
0 Replies

8. Shell Programming and Scripting

Need shell script to read two file at same time and print out in single file

Need shell script to read two file at same time and print output in single file Example I have two files 1) file1.txt 2) file2.txt File1.txt contains Aaa Bbb Ccc Ddd Eee Fff File2.txt contains Zzz Yyy Xxx (10 Replies)
Discussion started by: sreedhargouda
10 Replies

9. Shell Programming and Scripting

compare 2 file and print difference in the third file URG PLS

Hi I have two files in unix. I need to compare two files and print the differed lines in other file Eg file1 1111 2222 3333 file2 1111 2222 3333 4444 5555 newfile 4444 5555 Thanks In advance (3 Replies)
Discussion started by: evvander
3 Replies
Login or Register to Ask a Question