Question: I have a script that goes through many different checks and I use the `success`, `failure` functions defined in `/etc/init.d/functions` to clearly show the action result on the terminal.

That works great, except in some cases where I print a bit more text, I then get the result box displayed *over my text*:

`/usr/share/app/lib/lib_mylib.so lib[ OK ]o matches as expected`

Where I'd like it to be displayed:

`/usr/share/app/lib/lib_mylib.so lib_mylib.so matches as expected [ OK ]`

Looking around I saw that `/etc/init.d/functions` is using a variable `RES_COL` to position where to print the result field. If `/etc/sysconfig/init` exists then `RES_COL` is taken from there, set by default to 60 chars. 

I've tried `export RES_COL=100` after sourcing `/etc/init.d/functions` to no avail.
Furthermore I'd like the result field to be **right-aligned** with the terminal window and not having to hard-code any value for that. Any idea?

Answer: 
With `awk` and associative [arrays](https://www.gnu.org/software/gawk/manual/html_node/Array-Example.html#Array-Example):

```
awk '!/^($|#)/{arr[$1]=$0}END{for(param in arr) print arr[param]}' /etc/sysctl.conf custom.conf

```

if order matters:

```
awk '!/^($|#)/{
  arr[$1] = $0
}
END {
  for(key in arr)
    print arr[key]
}' /etc/sysctl.conf custom.conf | sort > hardened.conf

```

`!/^($|#)/` - ignore commented or empty lines  

`{arr[$1]=$0}` - store each line into arr, associating it to the kernel param; the line is updated everytime it sees the same param (i.e. from `custom.conf` as that is the last file to be read)  

`END{for(param in arr) print arr[param]}` - after all the input has been read, print the associated line for each kernel parameter.
Set `IFS=$'\n'` and it wont treat spaces as new lines.