HI
I need to concatenate two files which are having headers. the result file should contain only the header from first file only and the header in second file have to be skipped.
file1:
name age
sriram 23
file2
name age
prabu 25
result file should be
name age
sriram 23
prabu 25
how to do this in script?
Thank in advance
Sriram
joeyg
September 15, 2008, 9:57am
2
> cat file1
name age
sriram 23
> cat file2
name age
prabu 25
> cat file1 >file3 ; tail +2 <file2 >>file3
> cat file3
name age
sriram 23
prabu 25
how to do this if i have n number of files
joeyg
September 15, 2008, 10:24am
4
The following example assumes that the input files are all in the format of "file*"
#! /usr/bin/bash
ls file* >my_list
rm big_file 2>/dev/null
first_f=1
while read zf
do
if [ $first_f -gt 0 ]
then
cat "$zf" >>big_file
first_f=0
else
tail +2 "$zf" >>big_file
fi
done <my_list
exit 0
Tytalus
September 15, 2008, 11:40am
5
sed q file1 > file.new;ls file[12] | xargs -i tail +2 {} >> file.new
format head=
name age
---------------
.
format content=
@<<<<<<<@>>>>>>
$name $age
.
open(FH,">out.txt") or die "Can not open file!";
select FH;
$^=head;
$~=content;
open(FH1,"<first.txt");
while(<FH1>){
if($.>1)
{
($name,$age)=split(" ",$_);
write;
}
}
close(FH1);
open(FH1,"<second.txt");
while(<FH1>){
if($.>1)
{
($name,$age)=split(" ",$_);
write;
}
}
close(FH1);
you can use
cat file2>>file1
it append file2 after file1.