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
# 8  
Old 12-07-2006
Python alternative:

Code:
#!/usr/bin/python
#name:test.py
import glob
for file in glob.glob("*.trf"):
     r = open(file)
     print header = r.readline().strip()
     r.close()

usage:
Code:
./test.py > outputfile

# 9  
Old 12-08-2006
#!/usr/local/bin/bash ;# ksh 2nd choice if bash not installed.
HDRSTR="unique string in every header"
DIR=/path/to/data/dir
OFL=/path/to/output/file
TMPFL=/tmp/zzz
cat /dev/null > $OFL
cd $DIR
for i in ls
do
cat $i >> $TMPFL
done
cat $TMPFL|sort -u > $OFL
CHK=`cat -n $OFL|grep $HDRSTR|cut -f1 -d' '`
TTL=`cat $OFL|wc -l`
cat $OFL|head -n $(($CHK-1)) > $OFL
cat $OFL|tail -n $(($TTL-$CHK)) >>$OFL

Okay, this hasn't been tested. It looks right, but the -1 on the penultimate line may not be needed... Hmmm.

Have fun.
# 10  
Old 12-08-2006
Code:
sed -n "1!p" file2006* > newfile

# 11  
Old 12-08-2006
awk '{if(fn != FILENAME)NR=1; if(NR != 1 )print $0;fn=FILENAME} ' filename*
# 12  
Old 12-08-2006
Note that any of these solutions that use shell-globbing instead of find will break on large numbers of files... I used find since I figured there might be thousands of those autogenerated files.
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