Replace integer string in a variable based on month?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Replace integer string in a variable based on month?
# 8  
Old 11-12-2018
Rudi -

I'm literally using your code you gave me. Version in first post.

Linux Version = Linux 2.6.39-400.128.17.el5uek x86_64

Code:
#!/bin/bash

GLP() { 
    IFS=";" T=($(locale abmon))
    IFS=- read EM EY <<< $(date -d "$(date +%Y-%m-1) -1 month" +%-m-%Y)
    IFS=- read SM SY <<< $(date -d "$(date +%Y-%m-1) -$(($2+0?$2:EM)) month" +%-m-%Y)
    _ENDPOV=${T[EM-1]}-${EY:4-$1}
    _STARTPOV=${T[SM-1]}-${SY:4-$1}
}

GLP "2" "2"

echo $_ENDPOV
echo $_STARTPOV

# 9  
Old 11-12-2018
Run with -x (xtrace) option set. What's your shell version?
# 10  
Old 11-12-2018
Hi Rudi -

It's as follows:

Quote:
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
Thanks!

------ Post updated at 11:49 AM ------

Interestingly enough, it works fine on this version of shell:

Quote:
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
Any thoughts?
# 11  
Old 11-12-2018
Yes - 3.2.25(1) is too old.
# 12  
Old 11-12-2018
:-( Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a string based on input

I am trying to read a value from a mapping file and would need to replace the value based on country parameter source_table_@ctry_final Expected final_var=source_table_aus_final If the country is in nz,usa,uk then final_var=diff_table_nz_final final_var=diff_table_usa_final like that... (10 Replies)
Discussion started by: Master_Mind
10 Replies

2. Shell Programming and Scripting

Replace variable value in first file based on records in second

Hello , I have below files a) File A <?xml version="1.0" encoding="UTF-8" standalone="no"?> <root xmlns="http://aaa/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema" version="2.0"> <project name="source"> <mapping name="m_Source"> <parameter... (3 Replies)
Discussion started by: Pratik4891
3 Replies

3. Shell Programming and Scripting

Find and replace string based on entries on another file

I have a file1 with different with multiple fields and records File2 has 2 fields. I want to find and replace strings in file1 based on file2 values (I Want an exact match i.e. for example: when searching for DT:3, Substr of DT:34 should not be matched) File2: DT:3 foo_err DT:34 bar_frr... (8 Replies)
Discussion started by: aydj
8 Replies

4. Shell Programming and Scripting

Moving files based on size (string to integer)

I have a log file that I want to archive out as it reaches 100MB. I am using the following to get the file size into a variable but get the error "line 5: filesize=$(wc -c < logfile.log) if then echo "is greater than 100M" else echo "is less than 100M" fi I'm sure there's something... (2 Replies)
Discussion started by: Flakman
2 Replies

5. Shell Programming and Scripting

Converting Month into Integer

okay so i run an openssl command to get the date of an expired script. Doing so gives me this: enddate=Jun 26 23:59:59 2012 GMT Then i cut everything out and just leave the month which is "Jun" Now the next part of my script is to tell the user if the the certificate is expired or not... (6 Replies)
Discussion started by: shade917
6 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

8. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

9. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

10. UNIX for Dummies Questions & Answers

Converting a String variable into Integer

Hi, I am passing a variable to a unix function. However when I try to assign the value to another variable like typeset -i I_CACHE_VAL=$2 Is this because of String to Integer conversion? I get an error. Please help me with thsi. Thanks (2 Replies)
Discussion started by: neeto
2 Replies
Login or Register to Ask a Question