How to Eliminate first line of multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Eliminate first line of multiple files
# 1  
Old 12-07-2006
How to Eliminate first line of multiple files

hi gurus ,,

I have multiple files with same file pattern..in a particular directory

for ex: file20061101.trf
file20061102.trf
file20061103.trf

Each of the file has a header as column names..

My questions is how can i eliminate the first row of each of these files and write it into a single file..

Can anyone help uup with a shell script..

i was thinking of looping each file and get the count and then do tail of -1 to a file..


but was not sure whether its the best method..if anyone had come across the situation please let me know

Appreciate any kind of information or help

Thanks n Regards
Sish
# 2  
Old 12-07-2006
try this one

Code:
#!/usr/bin/perl
$x=1; #first file who will open will be file20061.trf change if you need
$xmax=9999; #change this as you need is the limite of files
$patternb="file2006"; #begin of filename
$patterne=".trf"; #end of filename
while($x!=$xmax){
$y=0;
@lines=();
$file=$patternb . $x . $patterne;
open(FD,"< $file")|| $y=1;
@lines=<FD>;
close(FD);
@lines=reverse(@lines);   #\
pop(@lines);                  # - Remove First Line
@lines=reverse(@lines);   #/
open(FD,"> $file") if $y!=1;
print FD @lines if $y!=1;
close(FD);
$x++; #and loop 
}

Smilie
ps: the script need to be at the same directory of the files
# 3  
Old 12-07-2006
Much easier with pipes than perl:
Code:
# Print a list of files with 'find', feed it into while loop.
# For each filename, open file, read and discard first line,
# print rest of file, while redirecting all output into 'output'
find ./ -iname 'file2006*' |
        while read FILE
        do
                ( read LINE ; cat ) < "${FILE}"
        done > output

# 4  
Old 12-07-2006
omg

hey i need to learn more about sh Smilie
# 5  
Old 12-07-2006
Any reason that you can't use good old tail? It has a '+' option that you can use to print lines from that line onward:
Code:
# cat test.sh
#!/bin/ksh
echo $1
echo $?

#tail +2 test.sh
echo $1
echo $?

Run tail +2 on each file through the while loop.
# 6  
Old 12-07-2006
Or...
Code:
awk 'FNR>1' file*.trf > outfile

# 7  
Old 12-07-2006
On a side note, funny how it is always whose is bigger, yet, when it comes to scripting/coding, it is always whose is smaller Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies

2. UNIX for Dummies Questions & Answers

Insert a line into multiple files

HI All, I want to know if it is possible to print the same message but into 2 different files in the same command? Something like . .. ... echo "Text" >> file1 && file2 this is because i creating a script which i use a log but i don't want to duplicate lines of command just to... (5 Replies)
Discussion started by: lordseiya
5 Replies

3. UNIX for Dummies Questions & Answers

Want to change common line from multiple files

Hi everyone, I've a requirement to modify an existing line which is common to multiple files. I need to replace that existing line with a new line. I've almost 900 ksh files to edit in the similar fashion in the same directory. Example: Existing Line: . $HOME/.eff.env (notice the "." at the... (3 Replies)
Discussion started by: kaleem.adil
3 Replies

4. Shell Programming and Scripting

insert filename into each line of multiple files

I need to insert <filename + comma> into each line of multiple files. Any idea how to script that? Regards, Manu (5 Replies)
Discussion started by: linux.yahoo
5 Replies

5. Shell Programming and Scripting

Script to eliminate files .rlogin

Hi guys, I'm try making to script for eliminate files rlogins. path1='/home/*' for i in `cat /etc/passwd |awk -F: '{print $6}'`; do if test "$i" = "$path1"; then echo $i cd $i if ; then echo "$i/.rhosts detectado"|mail -s "rhosts" root ... (14 Replies)
Discussion started by: nena_redbalon
14 Replies

6. Shell Programming and Scripting

Eliminate double void line

Hi, I need to eliminate each second void line in a text file. novus MILLENNIO ineo frater in episcopatus , presbyter et diacon|diaconus , (1 Reply)
Discussion started by: mjomba
1 Replies

7. UNIX for Dummies Questions & Answers

awk, extract last line of multiple files

Hi, I have a directory full of *.txt files. I would like to print the last line of every file to screen. I know you can use FNR for printing the first line of each file, but how do I access the last line of each file? This code doesn't work, it only prints the last line of the last file:BEGIN... (5 Replies)
Discussion started by: Liverpaul09
5 Replies

8. Shell Programming and Scripting

renaming multiple files with first line of content

Hi , I want to rename multiple files with their first line bar the first character + the extension .qual. For the example below the filename should read 7180000000987.qual. I have trawled through different threads for 2 days and I don't seem to find anything I can adopt for this task :confused: ... (7 Replies)
Discussion started by: Bruno
7 Replies

9. Shell Programming and Scripting

how to view last line of multiple files

Dear All, can anybody help me out in generating a command that can be used to view the last line of multiples files. e.g: file 1 contains 100 records file 2 contains 200 records file 3 contails 300 records now i need a command that can be used to display the last line of each... (7 Replies)
Discussion started by: jojo123
7 Replies

10. Shell Programming and Scripting

Shell script help to eliminate files of todays date

Hi I am very new to shell scripting and have written a script (below). However the directory I am searching will contain a file with a .trn extension each day which I want to eliminate. Each day the file extension overnight will change to trx, if this fails I want to know. Basically what I... (2 Replies)
Discussion started by: richM
2 Replies
Login or Register to Ask a Question