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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting want to concatenate multiple files based on the rest of ls -lrt
# 1  
Old 08-27-2010
want to concatenate multiple files based on the rest of ls -lrt

Code:
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 ?

Last edited by pludi; 09-02-2010 at 02:00 AM.. Reason: code tags, please...
# 2  
Old 08-27-2010
concatenate files last modified in current month.
Code:
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:
Code:
ls -ltr | awk ' $6=="Jun" { system("cat " $NF " >> single_file.txt") } '

# 3  
Old 08-31-2010
i wanted to put this inside the script
but am getting the below error for that


Code:
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


Last edited by pludi; 09-02-2010 at 02:00 AM..
# 4  
Old 08-31-2010
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:
Code:
$6==d { system("cat " $NF " >> /home/data/singlefile ) }

I think it should be:
Code:
$6==d { system("cat " $NF " >> /home/data/singlefile" ) }

Note the double quote.
# 5  
Old 09-01-2010
Code:
#!/bin/sh


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





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

getting the below error


Code:
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

Moderator's Comments:
Mod Comment At over 80 posts, you should know how to use code tags

Last edited by pludi; 09-02-2010 at 02:01 AM..
# 6  
Old 09-01-2010
Quote:
Originally Posted by mail2sant
#!/bin/sh


ls -ltr /home/data/log/ | `awk -vd=`date +"%b"` ' $6==d { system("cat " $NF " >> /home/data/singlefile" ) }'`
You don't need the backquotes (before awk and after command).
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate column values when header is Matching from multiple files

there can be n number of columns but the number of columns and header name will remain same in all 3 files. Files are tab Delimited. a.txt Name 9/1 9/2 X 1 7 y 2 8 z 3 9 a 4 10 b 5 11 c 6 12 b.xt Name 9/1 9/2 X 13 19 y 14 20 z 15 21 a 16 22 b 17 23 c 18 24 c.txt Name 9/1 9/2... (14 Replies)
Discussion started by: Nina2910
14 Replies

2. Shell Programming and Scripting

Concatenate files based on names

Dear all, I have a list of files and I woulk like to concatenate some of them based on their name. Basically my files are names like that: file1_abcd_other_useless_letters_1_C1.txt file1_abcd_other_useless_letters_1_C2.txt file1_xywz_other_useless_letters_1_C1.txt... (4 Replies)
Discussion started by: giuliangiuseppe
4 Replies

3. Shell Programming and Scripting

Merge two input files and concatenate the rest

Hi Guys, I need a help to creating a bash script to merging two files that containing not in order pattern into single file also within that single file I need to concatenate and manipulate the string from two files. Appreciate for any kind help given. Thanks. Here are the input files:... (3 Replies)
Discussion started by: jabriel
3 Replies

4. Shell Programming and Scripting

Concatenate select lines from multiple files

I have about 6000 files of the following format (three simplified examples shown; actual files have variable numbers of columns, but the same number of lines). I would like to concatenate the ID (*Loc*) and data lines, but not the others, as shown below. The result would be one large file (or... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

5. Shell Programming and Scripting

How to concatenate the files based upon the file name?

Hi Experts, I am trying to merge multiple files into one file based upon the file name. Testreport_Server1.txt ============ MonitoringReport_Server1.txt============ CentralReport_Server1 Here two files containing server1 should be merged into one file? How can i do... (16 Replies)
Discussion started by: sharsour
16 Replies

6. Shell Programming and Scripting

Divide an EBCDIC files into multiple files based on value at 45-46 bytes

Hi All, I do have an EBCDIC file sent from the z/os , this file has records with different record types in it, the type of record is identified by bytes 45-46 like value 12 has employee record value 14 has salaray record and etc.... we do now want to split the big ebcdic file into multiple... (3 Replies)
Discussion started by: okkadu
3 Replies

7. UNIX for Dummies Questions & Answers

What does total no. of files in ls -lrt o/p means?

when we fire ls -lrt command we see o/p as total 16 drwx------ 9 root root 8192 May 8 2002 lost+found drwxr-xr-x 2 root root 512 Jun 14 2002 TT_DB drwxrwxr-x 2 root root 512 Jul 31 2002 mail here total no. of files is always greater than... (4 Replies)
Discussion started by: Jcpratap
4 Replies

8. Shell Programming and Scripting

Concatenate columns from multiple files

Hi all, I want the 2nd column of every file in the directory in a single file with the file name as column header. $cat file1.txt a b c d e f $cat file2.txt f g h g h j $cat file3.txt a b d f g h (2 Replies)
Discussion started by: newbie83
2 Replies

9. Shell Programming and Scripting

Concatenate multiple lines based.

Hello, I have been searching the forum for concatenation based on condition. I have been close enough but not got th exact one. infile: -----DB_Name ABC (X, Y,Z). DB_Name DEF (T). DB_Name GHI (U ,V,W). Desired Output file should be: ---------------------------DB_Name ABC... (8 Replies)
Discussion started by: indrajit_u
8 Replies

10. Shell Programming and Scripting

Find multiple patterns on multiple lines and concatenate output

I'm trying to parse COBOL code to combine variables into one string. I have two variable names that get literals moved into them and I'd like to use sed, awk, or similar to find these lines and combine the variables into the final component. These variable names are always VAR1 and VAR2. For... (8 Replies)
Discussion started by: wilg0005
8 Replies
Login or Register to Ask a Question