Skip to content

possible direction? #1

Open
Open
@mikeserv

Description

@mikeserv

So, we talked about this the other day. I actually got back in the chat room last night, though I don't think you've seen it - (your profile indicates you haven't logged in since)...

Anyway, here is a really rough 1/4 way there sed implementation - (updated):

tab='       ' nl='
'; LC_ALL=C \
sed '/^#####/,/^#####/d
    /["#@]/!d
    /^###[^#]/,/^#['"$tab"' ]*$/!d
    /^#/{   /^###[^#]/!d
};  s/[]|\\$^*[]/\\&/g
    s/\([^ '"$tab#].*[^ $tab"'"#]\).*/\1/
    /^#[ '"$tab"'#]*\(.*\)/{ 
        s//\1/;h;d
};  s/^[^"]*"\(.*\)/"|\1|/
    //!G
    s/@\(.*\)\n\(.*\)/\2\1@|/
    s/^[^"]/@|@&/
'

I read your updated notes this morning - and I think I'm beginning to understand better. I'll be honest about this - my hope is that doing this would help me to learn to use git. I don't know how - and I'd really like to. This is probably obvious considering I posted this as an issue. While that may be true - it's not your issue but mine. Yours works - this doesn't... yet. I'm hoping we can help each other - because I really am very good with sed and portable shell-script, but not much else.

This update actually does less than before. It does not print working sed script. It parses a config file and prints something very near to sed script that should be easily transformable depending on intended action. Given the following input:

###LIVE_###
@AWS_ACC$ESS_KEY_ID
        "fi|ll* in with real value"
@AWS_SECRET_ACCESS_KEY
        "fill in with real value"
@MERCHANT_ID
        "fill in with real value"
@APPLICATION_NAME
        "fill in with real value"
#^this is the AWS application name^#
;lkj;lkj
#LIVE_APPLICATION_NAME[2]="/fill in walue/!"

#
###SANDBOX_###
@AWS_ACCESS_KEY_ID
        "fill in with real value"
@AWS_SECRET_ACCESS_KEY
        "fill in with real value"
@APPLICATION_NAME
        "fill in with real value"
@MERCHANT_ID
        "fill in with real value"
#

It prints...

@|@LIVE_AWS_ACC\$ESS_KEY_ID@|
"|fi\|ll\* in with real value|
@|@LIVE_AWS_SECRET_ACCESS_KEY@|
"|fill in with real value|
@|@LIVE_MERCHANT_ID@|
"|fill in with real value|
@|@LIVE_APPLICATION_NAME@|
"|fill in with real value|
@|@SANDBOX_AWS_ACCESS_KEY_ID@|
"|fill in with real value|
@|@SANDBOX_AWS_SECRET_ACCESS_KEY@|
"|fill in with real value|
@|@SANDBOX_APPLICATION_NAME@|
"|fill in with real value|
@|@SANDBOX_MERCHANT_ID@|
"|fill in with real value|

Basically it wants input like:

  ###SECTION###
  @SEARCH_VALUE1
     "replace value1"
  @SEARCH_VALUE2
       "replace value2"
  #

where SECTION replaces the first @ character on any SEARCH_VALUE line.
On ###SECTION### and SEARCH_VALUE lines all whitespace is removed.
There can be multiple "replace value" lines per SEARCH_VALUE.
On "replace value" lines all characters before the first and following the last " are removed
So the leading whitespace there doesn't matter. Blank lines are ignored.
In fact, all lines not beginning w/ 3 hashes, or containing a @ or at least two " are ignored.
All lines, that is, but a line beginning with a single # and containing any amount of trailing whitespace.
Those lines serve to delimit each SECTION
Oh, and for SECTION lines the trailing hashes are optional - they don't matter.
Any line not within a ###SECTION through ^#$ range is ignored - even if it happens to match one of those 3 types of lines that aren't ignored.
And any lines within that range that begin with a hash are ignored as well - even if they contain two or more quotes and/or a @.

Probably you can see where my fatal flaw was though with the (SEARCH/replace) labels - those need to be interchangeable. I believe I am working toward that.

I am very interested to know what you think though - as, again, my understanding it admittedly limited. Do you think it could be a workable direction?

My roughly imagined workflow looks like:

  1. shell accepts args and calls first sed/grep to select only relevant SECTION ranges in config file.
  2. those config lines are passed to this sed which translates its input into working sed script
  3. last sed reads it as a script and performs file edits as necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions