Shell script to identify the number of files and to append data

Hi

I am having a question where I have to
1) Identify the number of files in a directory with a specific format
and if the count is >1 we need to concatenate those two files into one file and remember that in the second file the header should not be copied. it should be form first file.
Could you please give some tips on this.

sample :

input files

abc123

abc234

def123

output files

abc

def

for example

file: abc123

col1|col2|col3

1|2|3

file: abc234

col1|col2|col3

4|5|6

output

file: abc

col1|col2|col3

1|2|3

4|5|6

thanks
Sunil

You didn't mention what is that specific format (for filename)?
Anyway,

say for abc files, you can do something like:

i=0
for file in abc*
do
  [ $i -eq 0 ] && cat $file > final_abc || tail  +2 $file >> final_abc
  i=$(( $i + 1 ))
done

the file formats are as below

20070101_20070630_20100524112157_DW_EXPORT_PAYMENTS.txt
20060101_20060630_20100524112157_DW_EXPORT_PAYMENTS.txt

20070101_20070630_20100524112157_DW_EXPORT_PRODUCTS.txt

the first two files should be written to asingle output file called DW_EXPORT_PAYMENTS.txt
and the last file will be renamed to DW_EXPORT_PRODUCTS.txt

"If I find that there is more than one file then only the concatenation should take place else simple rename should occur"

Hope I am clear

try something like..

for pattern in $(ls -1 | awk -F "[_.]" '{print $6}'| sort -u)
do
	i=0
	for file in *${pattern}.txt
	do
		[ $i -eq 0 ] && cat $file > ${pattern}.final || tail  +2 $file >> ${pattern}.final
		i=$(( $i + 1 ))
	done
done

Try:

awk 'FILENAME~/[0-9]{3}$/ {
     p=substr(FILENAME,1,3)
     if ( o == p  && $1 ~ /col1|col2|col3/ ) {getline}
     print >p
     o=p }' *