Combine file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine file
# 1  
Old 03-02-2006
Combine file

Hi all,

If I have 4 kind of files , and each file have different date, all of them are flat file and have the same 4 fields
Date|ID|Class|City

english.20060228.dat
02/28/2006|ABC|ENG|San Tomas
02/28/2006|BCD|ENG|San Jone
02/28/2006|AFD|ENG|San Luis
02/28/2006|ADD|ENG|San Mateo

english.20060227.dat
02/27/2006|ABC|MTH|San Tomas
02/27/2006|BBD|ENG|San Jone
02/27/2006|HFD|ENG|San Luis
02/27/2006|RRR|PHY|San Mateo


Spanish.20060228.dat
02/28/2006|AXC|ENG|San Tomas
02/28/2006|BXD|ENG|San Jone
02/28/2006|AXD|ENG|San Luis
02/28/2006|AXD|ENG|San Mateo

Spanish.20060227.dat
02/27/2006|ANC|SPASan Tomas
02/27/2006|BND|HUH|San Jone
02/27/2006|AND|WEL|San Luis
02/27/2006|AND|TET|San Mateo


france.20060228.dat
02/28/2006|AMC|EWW|San Tomas
02/28/2006|BMD|WRE|San Jone
02/28/2006|AMD|RGG|San Luis
02/28/2006|AMD|EWW|San Mateo

france.20060227.dat
02/27/2006|QYQ|MTH|San Tomas
02/27/2006|BYD|ENG|San Jone
02/27/2006|AYD|ENG|San Luis
02/27/2006|AYD|PHY|San Mateo


Dummy.20060228.dat
02/28/2006|AKC|ENGD|San Tomas
02/28/2006|BKD|ENGD|San Jone
02/28/2006|AKD|ENGD|San Luis
02/28/2006|AKD|ENGD|San Mateo

Dummy.20060227.dat
02/27/2006|AIC|MTHD2|San Tomas
02/27/2006|BID|ENGD2|San Jone
02/27/2006|AID|ENGD2|San Luis
02/27/2006|AID|PHYD2|San Mateo

how do I write a code to combine all file english*.dat , spanish*.dat , france*.dat NOT DUMMY.dat and it should have combine.date.log and combine.date2.log ( and new containt sort by ID and CLASS).... like combine.20060227.log , combine.20060228.log

How it can go to this directory and do in one script ??
can we do it in korn shell ?

Thanks

Last edited by sabercats; 03-02-2006 at 04:54 PM..
# 2  
Old 03-02-2006
Something to start with - you take it from here!
Code:
#!/bin/ksh

#file='Dummy.20060227.dat'

for file in *.dat
do
   nd="${file%.*}"
   name="${nd%%.*}"
   date="${nd##*.}"
   #echo "name->[${name}] date->[${date}]"
   cat "${file}" >> "combine.${date}.log"
done

# 3  
Old 03-02-2006
It is not what I expected . The comebine. date.log will contain english.date.log,spanish.date.log,france.date.log and NOT DUMMY.date.log, some how your code is combine.english.date.log and it is exactly english.date.dat
# 4  
Old 03-02-2006
Quote:
Originally Posted by sabercats
It is not what I expected . The comebine. date.log will contain english.date.log,spanish.date.log,france.date.log and NOT DUMMY.date.log, some how your code is combine.english.date.log and it is exactly english.date.dat
that's not what I'm seeing here given your files and the naming conventions.
Either way - try to understand the code and change it the way you want it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need to combine two lines in a file based on first character of each line in a file

Hi, I have a requirement where I need to combine two lines in a file based on first character of each line in a file. Please find the sample content of the file below: Code: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi,... (1 Reply)
Discussion started by: jayaP
1 Replies

2. UNIX for Dummies Questions & Answers

Need to combine two lines in a file based on first character of each line in a file

Hi, I have a requirement where I need to combine two lines in a file based on first character of each line in a file. Please find the sample content of the file below: Code: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi,... (1 Reply)
Discussion started by: jayaP
1 Replies

3. Shell Programming and Scripting

Combine two parts of a file

Hello All, I have a file like this APPLY ( 'INSERT INTO brdcst_media_cntnt ( cntnt_id ,brdcst_media_cntnt_cd ,cntnt_prvdr_cd ,data_src_type_cd ,cntnt_titl_nm ,cntnt_desc ,batch_dt ,batch_id ) VALUES ( :cntnt_id (3 Replies)
Discussion started by: nnani
3 Replies

4. Shell Programming and Scripting

Combine in single file

I have 2 files: phone.txt and mobile.txt ex. phone.txt MOBILENO|DISABLE_DATE 919687877754|9/1/2011| 919687877762|9/1/2011| 919687880573|9/1/2011| 919687882658|9/2/2011| Ex. mobile.txt MOBILENO |TIME 919687880573|2011-09-17 12:23:40| 919687882658|2011-10-10 21:15:33|... (4 Replies)
Discussion started by: khingx
4 Replies

5. Shell Programming and Scripting

combine two values within a file

Can you guys help me, I have two files: File A 60|11111| 601|11111| 6012|11111| 6013|11111| 60142|11111| File B 642|11111| 659|11111| 852|11111| 6012|11111| 6013|11111| I want to combine the two file into: File C 60|642| 601|642| 6012|642| (2 Replies)
Discussion started by: lurak
2 Replies

6. Shell Programming and Scripting

want to combine multiple file into one

Below are the list of files I have I want to consolidate the monthly log in the one file Eg : all the july log to be moved to log_july_full.txt inside the script Path : /home/user/data/log/ Jun 6 04:08 data_log-2010.05.30-10:04:08.txt Jun 13 01:38 data_log-2010.06.06-10:04:08.txt... (3 Replies)
Discussion started by: mail2sant
3 Replies

7. Shell Programming and Scripting

Help me to combine two file

Hi, can anybody help me. I want to combine these two file into one horizontally. 1st File: ... 10:00 10:01 10:02 10:03 10:04 10:05 ... 2nd File: ... 0715 10:00 Caps: 50 0715 10:01 Caps: 65 0715 10:02 Caps: 75 0715 10:04 Caps: 50 0715 10:05 Caps: 87 (3 Replies)
Discussion started by: lurak
3 Replies

8. UNIX for Dummies Questions & Answers

How do I combine the last 2 lines of a file

I tried to put the history line number and the date into the file with one command, and failed. Can't figure out how to get the date variable substituted for the last space captured. history | tail -1 | sed -e 's/.\{7\}/&/g' | head -1 | sed 's/ $/$date/' Result was: 729 $date So, I... (8 Replies)
Discussion started by: jimbob75
8 Replies

9. Shell Programming and Scripting

How to combine first,second and third fields in a file

Hi Guys, I have a file as follows: 1 2 3 There are 5 spaces between 1 and 2 and one space between 2 and 3. I want: 123 How can I do this using awk? I tried using: (8 Replies)
Discussion started by: npatwardhan
8 Replies

10. Shell Programming and Scripting

combine multiple .xl file

Hi Friends, Is it possible in Unix ? The requirement is ============= Create a unix shellscript that combines multiple excel files into one. Note : it is possible for data files.but the requirement is for excel file (4 Replies)
Discussion started by: bikas_jena
4 Replies
Login or Register to Ask a Question