The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
combine multiple .xl file bikas_jena Shell Programming and Scripting 4 12-11-2007 12:12 PM
sed, grep, cut or combine? maskot Shell Programming and Scripting 4 01-10-2007 06:46 AM
combine two files fredao1 Shell Programming and Scripting 1 01-08-2007 05:29 PM
Combine two lines superprg UNIX for Dummies Questions & Answers 10 02-01-2006 04:47 AM
how to combine two files tao UNIX for Dummies Questions & Answers 4 03-21-2002 06:38 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-02-2006
Registered User
 

Join Date: Feb 2006
Posts: 66
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 12:54 PM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-02-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
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
Reply With Quote
  #3 (permalink)  
Old 03-02-2006
Registered User
 

Join Date: Feb 2006
Posts: 66
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
Reply With Quote
  #4 (permalink)  
Old 03-02-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
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.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0