Sponsored Content
Top Forums Shell Programming and Scripting [All variants] Change settings Post 302992684 by Chubler_XL on Tuesday 28th of February 2017 02:25:43 PM
Old 02-28-2017
OK sorry for the misunderstanding.

Here is a GNU awk solution:

Code:
gawk -v ADD_DAYS=300 '
/#DATEA/ {
  DT = mktime(gensub(/-/, " ", "g", $2) " 0 0 0")
  DT += 24*60*60*ADD_DAYS
  printf "VALUEA\n%s\n", $2
}
/#VALUE TITLE/ { print gensub(/.*"([^"]+)"/, "\\1","g") }
/#SETTINGSEND/ { print strftime("\nVALUEB\n%Y-%m-%d", DT) }
!/^#/' settings.txt

and here is bash version:

Code:
#!/bin/bash
ADD_DAYS=300
while read line
do
    if [[ "$line" = \#DATEA\ * ]]
    then
       DA=${line#*DATEA }
       DT=$(date -d "$DA + ${ADD_DAYS}days" +%Y-%m-%d)
       printf "VALUEA\n%s\n" "$DA"
    fi
    if [[ "$line" = \#VALUE\ TITLE=* ]]
    then
        line=${line%\"}
        echo "${line#*\"}"
    fi
    [[ "$line" = \#SETTINGSEND* ]] && printf "\nVALUEB\n%s\n" "$DT"
    [[ "$line" = \#* ]] || echo "$line"
done < settings.txt

edit: This bash solution uses a case statement, which I think looks a bit cleaner than the one above:

Code:
#!/bin/bash
ADD_DAYS=300
while read line
do
    case "$line" in
        [#]DATEA\ *)
           DA=${line#*DATEA }
           DT=$(date -d "$DA + ${ADD_DAYS}days" +%Y-%m-%d)
           printf "VALUEA\n%s\n" "$DA" ;;
        [#]VALUE\ TITLE=*)
            line=${line%\"}
            echo "${line#*\"}" ;;
        [#]SETTINGSEND*) printf "\nVALUEB\n%s\n" "$DT" ;;
        [#]*) ;;
        *) echo "$line" ;;
    esac
done < settings.txt


Last edited by Chubler_XL; 02-28-2017 at 03:38 PM..
This User Gave Thanks to Chubler_XL For This Post:
 

9 More Discussions You Might Find Interesting

1. Solaris

how do I change locale settings?

I support a product which writes to log files and it's currently formatting the date in US format. I've established this is due to these settings: account1# locale -k d_fmt t_fmt d_fmt="%m/%d/%y" t_fmt="%H:%M:%S" If I log on with a different account the settings are different: ... (1 Reply)
Discussion started by: m223464
1 Replies

2. UNIX for Dummies Questions & Answers

How to change root's .profile settings

As a regular (non-root) user on Unix servers I'm accustomed to changing my .profile file to set paths that I frequently use, etc. I am trying to learn unix and set up a test server running SunOS 5.8. When I login as root I don't see a .profile file that belongs to root wherein I could change the... (1 Reply)
Discussion started by: FredSmith
1 Replies

3. HP-UX

command to change duplex settings..

Hi Folks, I want the command to change the duplex settings of a HP-UX server. Thanks in advance. Sagar. (2 Replies)
Discussion started by: sag71155
2 Replies

4. Solaris

effect of change of mpd preferred path settings

Hello All, In the output of the command "mpdcontrol -no xlist", I found that, some of the preferred paths are marked as "err". You can see the output below: # mpdcontrol -noxlist Unit Dev# MPD_ID/Policy DeviceName FC_AL DevMajMin IOcnt State... (0 Replies)
Discussion started by: sundar3350
0 Replies

5. Solaris

Putty : Change default settings (solved)

Hi, I use to work on solaris via putty and always on session start - i use to increase the font to 14 bold - capture session output to a file my requirement) to make these changes permanent, so that i need not to change the settings everytime i connect via putty please advice. ... (0 Replies)
Discussion started by: saurabh84g
0 Replies

6. AIX

Settings change in aix

Hi Can any one tell the procedure to change the maxpout and minpout settings on AIX (1 Reply)
Discussion started by: newtoaixos
1 Replies

7. Red Hat

Change user settings..

Hi, I have 48 cores in my server. I want to assign 50% of the cores to certain programs and rest to some other programms. I found the command "taskset" very good option to assign cpu afinity to already running programms or newly created programms. But the problem is even if i set a cron to... (1 Reply)
Discussion started by: Rantu
1 Replies

8. UNIX for Dummies Questions & Answers

Change default settings of nslookup

how and where can i change permanent the settings of nslookup? each time i change it by doing nslookup set timeout=2 the nslookup , does not save the settings , how can i do it in permanent way? (2 Replies)
Discussion started by: prpkrk
2 Replies

9. Shell Programming and Scripting

[All variants] remove first pair of parentheses

How to remove first pair of parentheses and content in them from the beginning of the line? Here's the list: (ok)-test (ok)-test-(ing) (some)-test-(ing)-test test-(ing) Desired result: test test-(ing) test-(ing)-test test-(ing) Here's what I already tried with GNU sed: sed -e... (6 Replies)
Discussion started by: useretail
6 Replies
LIBBASH(7)							  libbash Manual							LIBBASH(7)

NAME
libbash -- A bash shared libraries package. DESCRIPTION
libbash is a package that enables bash dynamic-like shared libraries. Actually its a tool for managing bash scripts whose functions you may want to load and use in scripts of your own. It contains a 'dynamic loader' for the shared libraries ( ldbash(1)), a configuration tool (ldbashconfig(8)), and some libraries. Using ldbash(1) you are able to load loadable bash libraries, such as getopts(1) and hashstash(1). A bash shared library that can be loaded using ldbash(1) must answer 4 requirments: 1. It must be installed in $LIBBASH_PREFIX/lib/bash (default is /usr/lib/bash). 2. It must contain a line that begins with '#EXPORT='. That line will contain (after the '=') a list of functions that the library exports. I.e. all the function that will be usable after loading that library will be listed in that line. 3. It must contain a line that begins with '#REQUIRE='. That line will contain (after the '=') a list of bash libraries that are required for our library. I.e. every bash library that is in use in our bash library must be listed there. 4. The library must be listed (For more information, see ldbashconfig(8)). Basic guidelines for writing library of your own: 1. Be aware, that your library will be actually sourced. So, basically, it should contain (i.e define) only functions. 2. Try to declare all variables intended for internal use as local. 3. Global variables and functions that are intended for internal use (i.e are not defined in '#EXPORT=') should begin with: __<library_name>_ For example, internal function myfoosort of hashstash library should be named as __hashstash_myfoosort This helps to avoid conflicts in global name space when using libraries that come from different vendors. 4. See html manual for full version of this guide. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <ril@ran4.net> SEE ALSO
ldbash(1), ldbashconfig(8), getopts(1), hashstash(1) colors(1) messages(1) urlcoding(1) locks(1) Linux Epoch Linux
All times are GMT -4. The time now is 06:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy