want to concatenate multiple files based on the rest of ls -lrt

uadm@4132> ls -lrt
-rw------- 1 uadm uadm 3811819 Jun  6 04:08 data_log-2010.05.30-10:04:08.txt
-rw------- 1 uadm uadm  716246 Jun 13 01:38 data_log-2010.06.06-10:04:08.txt
-rw------- 1 uadm uadm     996 Jun 13 04:00 data_log-2010.06.06-10:04:22.txt
-rw------- 1 uadm uadm    7471 Jun 20 02:03 data_log-2010.06.13-10:04:09.txt
-rw------- 1 uadm uadm 2004080 Jun 20 04:01 data_log-2010.06.13-10:04:25.txt
-rw------- 1 uadm uadm      20 Jun 27 02:06 data_log-2010.06.20-10:04:09.txt
-rw------- 1 uadm uadm 2522123 Jun 27 04:05 data_log-2010.06.20-10:04:23.txt
-rw------- 1 uadm uadm      20 Jul  4 02:04 data_log-2010.06.27-10:04:09.txt
-rw------- 1 uadm uadm    2336 Jul  4 04:04 data_log-2010.06.27-10:04:08.txt
-rw------- 1 uadm uadm  620726 Jul 10 09:43 data_log-2010.07.04-10:04:09.txt
-rw------- 1 uadm uadm   24022 Jul 11 04:04 data_log-2010.07.04-10:04:21.txt
-rw------- 1 uadm uadm 3827432 Jul 18 02:02 data_log-2010.07.11-10:04:08.txt

So I want to write a script so to combine those files beased on the months

Eg: in that list I can see the log files for june month and july month

I want to combine logs of the june month file into the single file .
I want to do this monthly wise
Can I know how I can do this ?

concatenate files last modified in current month.

ls -ltr | awk -vd=`date +"%b"` ' $6==d { system("cat " $NF " >> single_file.txt") } '

if you just want to concatenate files of June, try this:

ls -ltr | awk ' $6=="Jun" { system("cat " $NF " >> single_file.txt") } '

i wanted to put this inside the script
but am getting the below error for that

sage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:          GNU long options:
        -f progfile             --file=progfile
        -F fs                   --field-separator=fs
        -v var=val              --assign=var=val
        -m[fr] val
        -W compat               --compat
        -W copyleft             --copyleft
        -W copyright            --copyright
        -W dump-variables[=file]        --dump-variables[=file]
        -W exec=file            --exec=file
        -W gen-po               --gen-po
        -W help                 --help
        -W lint[=fatal]         --lint[=fatal]
        -W lint-old             --lint-old
        -W non-decimal-data     --non-decimal-data
        -W profile[=file]       --profile[=file]
        -W posix                --posix
        -W re-interval          --re-interval
        -W source=program-text  --source=program-text
        -W traditional          --traditional
        -W usage                --usage
        -W version              --version

To report bugs, see node `Bugs' in `gawk.info', which is
section `Reporting Problems and Bugs' in the printed version.

gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.

Examples:
        gawk '{ sum += $1 }; END { print sum }' file
        gawk -F: '{ print $1 }' /etc/passwd
mt.sh: line 5:  $6==d { system("cat " $NF " >> /home/data/singlefile ) }: No such file or directory

I don't know what's gone wrong since you didn't post your script.
But from the snippet you posted I notice something that might be the cause of your problem:

$6==d { system("cat " $NF " >> /home/data/singlefile ) }

I think it should be:

$6==d { system("cat " $NF " >> /home/data/singlefile" ) }

Note the double quote.

#!/bin/sh


ls -ltr /home/data/log/  | `awk -vd=`date +"%b"` ' $6==d { system("cat " $NF " >> /home/data/singlefile" ) }'`

=============

getting the below error

Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:          GNU long options:
        -f progfile             --file=progfile
        -F fs                   --field-separator=fs
        -v var=val              --assign=var=val
        -m[fr] val
        -W compat               --compat
        -W copyleft             --copyleft
        -W copyright            --copyright
        -W dump-variables[=file]        --dump-variables[=file]
        -W exec=file            --exec=file
        -W gen-po               --gen-po
        -W help                 --help
        -W lint[=fatal]         --lint[=fatal]
        -W lint-old             --lint-old
        -W non-decimal-data     --non-decimal-data
        -W profile[=file]       --profile[=file]
        -W posix                --posix
        -W re-interval          --re-interval
        -W source=program-text  --source=program-text
        -W traditional          --traditional
        -W usage                --usage
        -W version              --version

To report bugs, see node `Bugs' in `gawk.info', which is
section `Reporting Problems and Bugs' in the printed version.

gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.

Examples:
        gawk '{ sum += $1 }; END { print sum }' file
        gawk -F: '{ print $1 }' /etc/passwd
mt.sh: line 5:  $6==d { system("cat " $NF " >> /home/data/singlefile" ) }: No such file or directory

Sep

You don't need the backquotes (before awk and after command).


ls -ltr /home/data/log/  | awk -vd=`date +"%b"` ' $6==d { system("cat " $NF " >> /home/data/singlefile" ) }'

I didn't run this, so there may be other issues, but that jumped out at me straight away.