cat to a file but retain header


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cat to a file but retain header
# 1  
Old 03-08-2012
cat to a file but retain header

Hi,
Is there a way to write to a txt file each day but retain the header on the file? I'm cat'ing 5 files into one .txt file each day but I want the new data to be written after the first 2 lines which are:

Code:
Progname  Size  Date  Owner
----------------------------

Basically I want my new files to be merged into the one but starting at line 3..

Any help much appreciated as usual!

Last edited by pludi; 03-08-2012 at 07:44 AM..
# 2  
Old 03-08-2012
Hi Grueben,

Use the append redirection:
Code:
$ cat file.txt >>file_with_header.txt

This User Gave Thanks to birei For This Post:
# 3  
Old 03-08-2012
Code:
awk 'NR==FNR{print;next}FNR>2' file1 file2 file3 ...

This User Gave Thanks to bartus11 For This Post:
# 4  
Old 03-08-2012
It's pretty simple with sed:
Code:
$ cat test.txt
Line 1
Line 2
Line 3
Line 4
Line 5
$ sed -ne '3,$p' test.txt 
Line 3
Line 4
Line 5

This User Gave Thanks to pludi For This Post:
# 5  
Old 03-09-2012
hi bartus,
wil u please explain the concept of NR==FNR
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. Shell Programming and Scripting

awk to retain header lines in output

The awk below executes and produces the current output, which is correct, except I can not seem to include the header lines # and ## in the output as well. I tried adding !/^#/ thinking that it would skip the lines with # and output them but the entire file prints as is. Thank you :). file ... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. UNIX for Dummies Questions & Answers

openssl dgst cat header problem

I am trying to run an old script to modify an image file with a modified header to bypass the md5 check but it comes up with an error message. The image file is for use on a Expressgate SSD so that I can add sqx files to it. This is a link from where I got the script:-... (3 Replies)
Discussion started by: r1speedyrider
3 Replies

4. Shell Programming and Scripting

retain last 1000 line in a file

I have large file with around 100k+ lines. I wanted to retain only the last 100 lines in that file. One way i thought was using tail -1000 filename > filename1 mv filename1 filename But there should be a better solution.. Is there a way I can use sed or any such command to change the... (9 Replies)
Discussion started by: nss280
9 Replies

5. Shell Programming and Scripting

Retain File Timestamp

There are directories of files that I have to run the dos2ux command on to get ride of the carriage return characters. Easy enough, but I have to retain the original timestamps on the files. I am thinking that I am going to have to strip off the timestamp for each file and convert it to unix time... (3 Replies)
Discussion started by: scotbuff
3 Replies

6. UNIX for Advanced & Expert Users

Retain Only specific number of file in Directory

I want to retain specific number of backup files in a directory.for example i want to retain only two latest backup file in backup directory. If number of backup files is greater than this policy that it will delete oldest file.Please Tell me whether this is possible or not. (2 Replies)
Discussion started by: ranvijaidba
2 Replies

7. Shell Programming and Scripting

Retain file permissions when saving .sh file from internet [OS X]

Hello. I have written a bash script that I am sharing with an OS X community I am a member of. The purpose of the script is to execute a series of commands for members without them having to get involved with Terminal, as it can be daunting for those with no experience of it at all. I have renamed... (4 Replies)
Discussion started by: baza210
4 Replies

8. Linux

Reading the header of a tar file(posix header)

say i have these many file in a directory named exam. 1)/exam/newfolder/link.txt. 2)/exam/newfolder1/ and i create a tar say exam.tar well the problem is, when i read the tar file i dont find any metadata about the directories,as you cannot create a tar containig empty directories. on the... (2 Replies)
Discussion started by: Tanvirk
2 Replies

9. UNIX for Dummies Questions & Answers

How to retain the header information of a file

Hi, I am using Bash shell to create some data and these data would be piped out to a file, let say output.txt. This output.txt I would like to add some extra header information such as comments, descriptions and general information on the text. I would like to know how could I maintain... (0 Replies)
Discussion started by: ahjiefreak
0 Replies

10. UNIX for Advanced & Expert Users

How to retain file permissions during FTP on Solaris 5.9 ?

Hi All, I am trying to ftp a file : -rw-rw-rw- 1 oraclepbdw dba filename.txt from Machine A ( where umask is 022) to Machine B (umask 022) but the file changes to -rw-rw-r-- 1 ftpamle3 ftaml filename.txt Dur some constraints the group of the users on either side... (3 Replies)
Discussion started by: gauravsachan
3 Replies
Login or Register to Ask a Question