How can we pass month value as per our requirements?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can we pass month value as per our requirements?
# 8  
Old 10-28-2015
I am not able to add 2 fileds at the begining and 2 fileds at the end of the file if the month fileds start from 6 th to 28 total 30 fileds is there
I have updated the code not geting correct output.
output should be dispaly 1 to 30
Code:
awk -F\| '
        {printf "%s|%s|%s", $1, $2,$3,4
         for (i=STARTM; i<=12; i++) printf "|%s", $(i+4)
         for (i=1; i<STARTM; i++) printf "|%s", $(i+4)
         for (i=STARTM; i<=12; i++) printf "|%s", $(i+16)
         for (i=1; i<STARTM; i++) printf "|%s", $(i+16)
         printf "%s" ,$29,$30
         printf "\n"
        }
' STARTM=5 file

# 9  
Old 10-28-2015
Why don't you post sample input, erroneous and desired output so we have sth to work upon?
You're printing $27 and $28 (NOV-M & DEC-M) when extra fields are $29 and $30?

---------- Post updated at 12:39 ---------- Previous update was at 12:35 ----------

And, you missed the format string and the $ when trying to print field 4.

---------- Post updated at 12:53 ---------- Previous update was at 12:39 ----------

Try
Code:
awk -F\| '
        {printf "%s|%s|%s|%s", $1, $2,$3, $4
         for (i=1; i<=24; i++) printf "|%s", $(5 + (STARTM-2+i)%12 + 12*int((i-1)/12))
         printf "|%s|%s\n", $29, $30
        }
' STARTM=8 file

# 10  
Old 10-28-2015
Rudic and Don
Thanks a lot for your help and quick replay
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

To pass one month range in sql script

Hi Guys, i am having .sql script which inserts data from one table to another table based on date condition, i need to pass range on based on how many number of months, for e.g set timing on; whenever sqlerror exit failure; spool myscript.log append accept start_date... (7 Replies)
Discussion started by: rohit_shinez
7 Replies

2. Shell Programming and Scripting

Need last month files after 10th of every month

Hi, I need all file names in a folder which has date >= 10th of last month, Example : files in folder AUTO_F1_20140610.TXT BUTO_F1_20140616.TXT CUTO_F1_20140603.TXT FA_AUTO_06012014.TXT LA_AUTO_06112014.TXT MA_AUTO_06212014.TXT ZA_AUTO_06232014.TXT Output: AUTO_F1_20140610.TXT... (9 Replies)
Discussion started by: nani1984
9 Replies

3. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

4. Shell Programming and Scripting

Convert From Month Number to Month Name

Hi, I have a script that accepts an input date from the user in yyyy-mm-dd format. I need to get the mm-dd part and convert it to month name. example: 2011-11-15 I want that to become "Nov 15" I don't have the GNU date, I am using an AIX os. Thanks. (1 Reply)
Discussion started by: erin00
1 Replies

5. Shell Programming and Scripting

How to pass current year and month in FOR LOOP in UNIX shell scripting?

Hi Team, I have created a script and using FOR LOOP like this and it is working fine. for Month in 201212 201301 201302 201303 do echo "Starting the statistics gathering of $Month partitions " done But in my scripts the " Month " variable is hard-coded. Can you please any one... (3 Replies)
Discussion started by: shoan
3 Replies

6. Linux

Pc Requirements

I am using a Pentium III and I want to change my cpu, which is better (AMD or dual core processor) for linux operating system. Thanks in advance for any help. (1 Reply)
Discussion started by: billcrosby
1 Replies

7. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

8. UNIX for Dummies Questions & Answers

Requirements for unix os

what are the requirements for unix os.i got now windows xp operating system.without disturbing windows xp i want to install unix os. (1 Reply)
Discussion started by: manohar12345678
1 Replies

9. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

10. Shell Programming and Scripting

Pass the first date and last date of previous month

Hi All, I need to run a job every month at the beginning of the month which is scheduled through autosys, lets say on 03/01/2010. I need to pass the last month's i.e February's first_date = 02/01/2010 and last_date = 02/28/2010 as variables to a stored procedure. Can somebody please pass... (2 Replies)
Discussion started by: vigdmab
2 Replies
Login or Register to Ask a Question