The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
make multiple line containing a pattern into single line VTAWKVT Shell Programming and Scripting 13 12-04-2008 06:40 PM
Adding Multiple Lines to Multiple Files dayinthelife Shell Programming and Scripting 2 06-04-2008 12:50 PM
Ksh Storing Multiple Files and reading each line in each file. developncode UNIX for Dummies Questions & Answers 1 04-08-2008 05:44 PM
Command line tool to join multiple .wmv files? karman OS X (Apple) 2 09-23-2007 02:52 AM
Cat'ing a multiple line file to one line djsal Shell Programming and Scripting 1 04-16-2007 09:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-07-2006
sish78 sish78 is offline
Registered User
  
 

Join Date: May 2006
Posts: 16
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 (permalink)  
Old 12-07-2006
sendai's Avatar
sendai sendai is offline
Registered User
  
 

Join Date: Dec 2006
Location: Brasil
Posts: 18
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 
}


ps: the script need to be at the same directory of the files
  #3 (permalink)  
Old 12-07-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,965
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 (permalink)  
Old 12-07-2006
sendai's Avatar
sendai sendai is offline
Registered User
  
 

Join Date: Dec 2006
Location: Brasil
Posts: 18
omg

hey i need to learn more about sh
  #5 (permalink)  
Old 12-07-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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 (permalink)  
Old 12-07-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Or...
Code:
awk 'FNR>1' file*.trf > outfile

  #7 (permalink)  
Old 12-07-2006
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0