Sponsored Content
Top Forums Shell Programming and Scripting how to increment days according to year & month Post 302391394 by Amit.Sagpariya on Monday 1st of February 2010 08:13:04 AM
Old 02-01-2010
Hi Reva,

Code:
#!/bin/ksh
let first_year=`head -1 a.dat | awk '{print $2}'`
cat a.dat | while read abc
do
 f_str=`echo $abc | awk '{print $1, $2, $3}'`
 b_str=`echo $abc | awk '{print $5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21}'`
 let year_num=`echo $abc | awk '{print $2}'`
        let month_num=`echo $abc | awk '{print $3}'`
        let month_day=`echo $abc | awk '{print $4}'`
 let diff_year=`echo "$year_num - $first_year" | bc`
 let out_year=`echo "$diff_year * 365" | bc`
        if [ $month_num -eq 1 ]
        then
                let out_month_day=`echo "$month_day + $out_year" | bc`
        elif [ $month_num -eq 2 ]
        then
                let out_month_day=`echo "$out_year + 31 + $month_day" | bc`
        elif [ $month_num -eq 3 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + $month_day" | bc`
        elif [ $month_num -eq 4 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + 31 + $month_day" | bc `
        elif [ $month_num -eq 5 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + 31 + 30 + $month_day" | bc`
        elif [ $month_num -eq 6 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + 31 + 30 + 31 + $month_day" | bc`
        elif [ $month_num -eq 7 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + 31 + 30 + 31 + 30 + $month_day" | bc`
        elif [ $month_num -eq 8 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + 31 + 30 + 31 + 30 + 31 + $month_day" | bc`
        elif [ $month_num -eq 9 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + $month_day" | bc`
        elif [ $month_num -eq 10 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + $month_day" | bc`
        elif [ $month_num -eq 11 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + $month_day" | bc`
        elif [ $month_num -eq 12 ]
        then
                let out_month_day=`echo "$out_year + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + $month_day" | bc`
        fi
        echo " ${f_str} ${out_month_day} ${b_str}" >> b.dat
 
 
done

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for tar and zip based on month & year

Hi Friends, I'm doing on script which finds all the files with time stamp and makes them tar and zip, based on their respective month&year. for instance "mar-2004.tar.zip" will contain all the files which was created/accessed/modified on mar-2004. like this the entire filesystem should be taken... (1 Reply)
Discussion started by: tuxfello
1 Replies

2. UNIX for Advanced & Expert Users

how to get the last month and year in UNIX

how to get the last month and year in UNIx (2 Replies)
Discussion started by: Vijay06
2 Replies

3. Programming

Interval year to month

Hi, I'm working on a Informix4gl module. I'm just trying to find out any built-in function to fetch only the year/month from an INTERVAL YEAR TO MONTH data value. Please let me know, if there are any functions to do this. If not, let me know for any alternative solutions to attain this. ... (5 Replies)
Discussion started by: dvah
5 Replies

4. Shell Programming and Scripting

want to get last year and month from the file

Hi I have files like abc_cd_20110302_123423 abc_cd_ef_20110301_123423 abc_cd_ef_20110403_123423 abc_ef_20110401_123423 I want to extract the the year and month associated with each file. I tried logfileyearmonth=`echo $logfile | awk -F_'{print $NF}'` Any other way can I... (6 Replies)
Discussion started by: dgmm
6 Replies

5. UNIX for Dummies Questions & Answers

Simpler next month year program

I have created this program to get the next month and year. Is there a simpler way. #!/bin/ksh string=`cat Date.txt` year=`echo $string | cut -c 1-4` month=`echo $string | cut -c 5-6` echo $year$month mon=`expr $month + 1` if ; then mon=0$mon echo $mon fi if ; then month=01 ... (2 Replies)
Discussion started by: w020637
2 Replies

6. Shell Programming and Scripting

How to list files that are not first two files date & last file date for every month-year?

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

7. Shell Programming and Scripting

How to find all files for same month and year?

Hi All, I find all files for same month and year lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 c.txt -rwxr-xr-x 1 user userg 1596 Mar 21 2012 d.txt -rwxr-xr-x 1 user userg 1596 Mar 22 2012 f.txt -rwxr-xr-x 1... (8 Replies)
Discussion started by: Makarand Dodmis
8 Replies

8. Shell Programming and Scripting

How to find all files other than first two dates & last date per month and year?

how to find all files other than first two dates & last date per month and year Hi All, lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 a.txt -rwxr-xr-x 1 user userg 1596 Mar 19 2012 b.txt -rwxr-xr-x 1 user userg ... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

9. UNIX for Beginners Questions & Answers

Best way to increment weeks based on fiscal start year

Hi Folks - I'm looking for the best way to to increment fiscal weeks - allow me to explain. At my one client, 10/01/17 was the beginning if year fiscal year 2018. Each week, I need to manage a unique set of variable that are updated in my application - they are called substitution variables.... (31 Replies)
Discussion started by: SIMMS7400
31 Replies
MSSQL_NUM_FIELDS(3)													       MSSQL_NUM_FIELDS(3)

mssql_num_fields - Gets the number of fields in result

SYNOPSIS
int mssql_num_fields (resource $result) DESCRIPTION
mssql_num_fields(3) returns the number of fields in a result set. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). RETURN VALUES
Returns the number of fields, as an integer. EXAMPLES
Example #1 mssql_num_fields(3) example <?php // Connect to MSSQL and select the database $link = mssql_connect('KALLESPCSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php', $link); // Select some data from our database $data = mssql_query('SELECT [name], [age] FROM [php].[dbo].[persons]'); // Construct a table echo '<table border="1">'; $header = false; // Iterate through returned results while ($row = mssql_fetch_array($data)) { // Build the table header if (!$header) { echo '<thead>'; echo '<tr>'; for ($i = 1; ($i + 1) <= mssql_num_fields($data); ++$i) { echo '<td>' . ucfirst($row[$i]) . '</td>'; } echo '</tr>'; echo '</thead>'; echo '<tbody>'; $header = true; } // Build the row echo '<tr>'; foreach($row as $value) { echo '<td>' . $value . '</td>'; } echo '</tr>'; } // Close table echo '</tbody>'; echo '</table>'; // Clean up mssql_free_result($data); mssql_close($link); ?> SEE ALSO
mssql_query(3), mssql_fetch_field(3), mssql_num_rows(3). PHP Documentation Group MSSQL_NUM_FIELDS(3)
All times are GMT -4. The time now is 09:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy