The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Check File Exists and compare to previous day file script rbknisely Shell Programming and Scripting 3 02-07-2008 11:53 AM
compare file size from a output file from a script moustik Shell Programming and Scripting 7 11-07-2007 10:17 AM
compare 2 file and print difference in the third file URG PLS evvander Shell Programming and Scripting 3 09-24-2007 06:52 AM
File Compare and Create New File with Diff guiguy UNIX for Advanced & Expert Users 7 02-28-2007 06:43 AM
How to compare prev day file to current day file Smurtzy Shell Programming and Scripting 1 12-05-2001 07:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-27-2006
sabercats sabercats is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 66
Sort and compare file

If I have 3 kinds of files in directory DATA1:
FileA.20060315.dat, FileB.20060315.dat, FileC.20060315.dat
FileC.20060316.dat
FileA.20060317.dat, FileB.20060317.dat
FileA.20060318.dat, FileB.20060318.dat, FileC.20060318.dat

If 3 files have the same date then run
$cat FileA.20060315.dat FileB.20060315.dat FileC.20060315.dat > FileD.20060315.dat and move these files to DATA2 .

if it doesnot have 3 files the same date then move it to DATA3 ???
How do you know what date to choose ?

Code:
#!/bin/ksh
cd  ./DATA1

for file in *.dat; do
ls -1 $file|awk -F"-" '{
        filedt = substr($2,1,8);
        {
    printf "%s\n",filedt
  }
        }'  >> checkit;
done
cat checkit | sort -n |uniq > date.srt
20060315
20060316
20060317
20060318
I get file sort by date then how I check date by date ? do you know ?
  #2 (permalink)  
Old 03-27-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try this:
Code:
#! /usr/bin/ksh

for i in FileA.* ; do
        if [[ -f FileB${i#FileA} && -f FileC${i#FileA} ]] ; then
                cat $i FileB${i#FileA} FileC${i#FileA} > FileD${i#FileA}
                mv $i FileB${i#FileA} FileC${i#FileA} FileD${i#FileA} ../DATA2
        fi
done
mv FileA.* FileB.* FileC.* ../DATA3 2>/dev/null
exit 0
  #3 (permalink)  
Old 03-27-2006
sabercats sabercats is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 66
wow, thanks, would you please explain for me the lines

if [[ -f FileB${i#FileA} && -f FileC${i#FileA} ]] ; then
cat $i FileB${i#FileA} FileC${i#FileA} > FileD${i#FileA}


I try to understand what does it mean.
if [[ -f FileB${i#FileA} && -f FileC${i#FileA} ]] --> if the fileB and file C have the same date with file A ???
  #4 (permalink)  
Old 03-27-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
FileB${i#FileA} = strip "FileA" off the front of the value of the variable, then prepend "FileB".
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0