Remove header from files: optimal performance


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove header from files: optimal performance
# 1  
Old 11-14-2007
Remove header from files: optimal performance

I need to concatenate about a thousand files (using a loop) on a UNIX server. Also, each file has a header row which is to be removed. Which of the following would give better performance?

tail+2 <filename> or sed '1,1d' <filename>

Or is there another, faster way?

Thanks,
Kaus
# 2  
Old 11-14-2007
here is my cut,

have a parent and child process

parent process - remove the header information from the file and pass it on the filename to the child process
till child completes wait on child's pid

child process - receive the filename from the parent and start appending the file to one common file

so atlast, there would be one file which contains the contents of all the 'n' files after header information is removed
# 3  
Old 11-14-2007
A faster way would be to write a small C program to read each file, find the second line in the file, and append the remainder of the file out to the new (concat'ed) file.
# 4  
Old 11-14-2007
one more,

Code:
ls file_list | while read file
do
awk ' NR != 1 { print }' $file 
done > one_big_output_file

# 5  
Old 11-14-2007
If the filenames are not too long (list too long error):

Code:
awk FNR\>1 *>final

Adjust * for your needs.

Use nawk or /usr/xpg4/bin/awk on Solaris.


If you have GNU tail:

Code:
tail -qn2 *>final


Last edited by radoulov; 11-14-2007 at 10:40 AM.. Reason: tail added
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove files having 0 byte or only header

Hi Team, I'm looking for a command which removes files having 0 byte of having only header line (1 line). My ETL process generates these files. Few files are not having header, in that case if no data from source, it will be 0 byte and few files are having header, in that case if no data from... (7 Replies)
Discussion started by: ace_friends22
7 Replies

2. Programming

[solved] how to remove header and footer

it still display header and footer header SQL*Plus: Release 10.2.0.1.0 - Production on Mon Sep 24 13:41:51 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production With the Partitioning, Real... (0 Replies)
Discussion started by: ment0smintz
0 Replies

3. UNIX for Dummies Questions & Answers

remove the header and footer using sed

I want to delete the header and footer in the file by using sed for that i ran the below script and my text file looks like emp.txt # This file contain employee # information abc 12300 34 'FGH' # This is confidential as per the firm rules. my intention is to remove the header... (8 Replies)
Discussion started by: vmachava
8 Replies

4. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

5. AIX

volume group lun sizes and no of file systems for optimal performance

Hello, It's been a while since I've done AIX..., but I'm planning a new TSM on AIX disk-only backup solution. I'm planning to make an AIX volume group out of 40 luns of 1 TB. I'm planning to create one big file system on here. The purpose for this is to use this as a device class FILE for... (5 Replies)
Discussion started by: smashingpumpkin
5 Replies

6. Shell Programming and Scripting

improve performance - replace $\| with $#@ and remove header and trailer records

Hi All, In my file i need to remove header and trailer records which comes in 1st line and last line respectively. After that i need to replace '$\|' with '$#@'. I am using sed command for this and its taking lot of time. Is there any other command which can be used to improve performance? ... (1 Reply)
Discussion started by: HemaV
1 Replies

7. Shell Programming and Scripting

bash ps; remove the header, sort and reinsert

Hi, I'm ssh'ing into a server using ruby and sending a one-liner to retrieve the output of the 'ps aux' command. So far, this is what I have: ps aux | sort -r -n -k3 | sed -e '1s/^/this is first\n/' | head -n10 With this I can insert a line at position 1, but I would rather extract the... (3 Replies)
Discussion started by: gekeha
3 Replies

8. SCO

How to remove date and page header from a printout

I have some HP4+ and HP5 printers printing from Unixware 7.1.4. The problem is that they print a page header with the date and page number. I can't seem to figure out how to stop this. These headers through the pagination off. (2 Replies)
Discussion started by: sladeburke
2 Replies

9. UNIX for Dummies Questions & Answers

Copy all the files with time stamp and remove header,trailer from file

All, I am new to unix and i have the following requirement. I have file(s) landing into input directory with timestamp, first i want to copy all these files into seperate directory then i want to rename these files without timestamp and also remove header,trailer from that file.. Could... (35 Replies)
Discussion started by: ksrams
35 Replies

10. Shell Programming and Scripting

remove header and footer rows

I would like to remove some lines from begining of file (header) and some lines from end of file (footer). The header/footer lines generated by web-browser when the user upload a file to my webserver. Example: -----------------------------7d62af20c052c Content-Disposition: form-data;... (2 Replies)
Discussion started by: seaky
2 Replies
Login or Register to Ask a Question