![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community. |
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| executing code on files in the sorted order -help! | epi8 | Shell Programming and Scripting | 1 | 05-20-2008 03:30 AM |
| sort by date and concatenate first three | jlarios | UNIX for Dummies Questions & Answers | 4 | 05-19-2008 02:49 PM |
| How to concatenate 2 files using awk? | pdtak | Shell Programming and Scripting | 2 | 03-12-2008 01:12 PM |
| Compare 2 sorted files | varungupta | Shell Programming and Scripting | 7 | 01-25-2008 01:07 PM |
| Concatenate date to file name | sierra_aar | UNIX for Dummies Questions & Answers | 4 | 02-14-2002 09:42 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
concatenate files sorted by date
I am a beginner in script writing, i tried to do the following
I have a set of files sorted by date in the format YYMMDD.s and .x and .r I need to concatenate a header file to these sets of files so I used the following code Code:
echo "enter Swath number"
read s
echo "please enter first date and MMDD press ENTER"
read i
echo "please enter last date and MMDD press ENTER"
read j
for((i; i <= j; i++))
do
cat NJSC_Alam_Ph1_Blk1_3D_HDR_S /ud/SPECSDATA/Final_SPS/Alam3D/Swath_${s}/08${i}.s > /ud/SPECSDATA/Final_SPS/Alam3D/Swath_${s}/08${i}_Final.s
cat NJSC_Alam_Ph1_Blk1_3D_HDR_R /ud/SPECSDATA/Final_SPS/Alam3D/Swath_${s}/08${i}.r > /ud/SPECSDATA/Final_SPS/Alam3D/Swath_${s}/08${i}_Final.r
cat NJSC_Alam_Ph1_Blk1_3D_HDR_X /ud/SPECSDATA/Final_SPS/Alam3D/Swath_${s}/08${i}.x > /ud/SPECSDATA/Final_SPS/Alam3D/Swath_${s}/08${i}_Final.x
done
I have 2 problems, the first on is that it doesn't do this for example if I enter the value for i and j to be 0530 and 0531 for 30 and 31 of May it searches for a file named 08345 instead of 080530. the other problem is how can i make the script to work for 2 different months? like I have the first file as 300508 and last file as 050608, the loop is not going o work there |
|
||||
|
Problem number 1 is you're mixing date math with integer math. You cannot add 1 to your "0530" and expect to get the next day. For example, there is no integer "0530". There is an integer "530", however, and if you add 1 to it you will get "531". ...NOT the "0531" that you need. And, as you mentioned, adding 1 to that will not get you into June.
The problem of shell date arithmetic is fairly difficult. See "Date math in Linux shell script?": Tech Support from Ask Dave Taylor! . When you do your comparison, you can test for your end condition in either of two ways:
I mention that because it's convenient to actually do the date math by:
-mschwage |
|
||||
|
Date variable definition
thank you for the reply, I get what you want to say fine, just one request:
what is the script command to identify a date variable? is there a variable called date? I tried something like date i, and dim i as date but it didn't work. I also tried "date -d ${i} +"%y%m%d"" but it said that i is not a command can you please help me on that? Last edited by docaia; 08-16-2008 at 03:54 AM.. Reason: adding some info |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|