Hi together,
unfortunately I am not a shell script guru - the following might touch
the depths of awk, substr, split, regexps, where I am still fighting with - but as always the boss needs a fast solution
So: I have the following USER/PASSWORD-installation-config-file, from where I want to read out the BELONGING TOGETHER user/passwords pairs to postprocess them in an sqlplus command to test if those users have already an account on the database:
Conditions here are:
=> always the same in the strings is "access.user=<username>" (resp. "admin.user=<username>")
=> always the same in the strings is also "access.password=<passwort>" (resp. "admin.passwort=<passwort>")
=> for a belonging together pair for example "admin.user/admin.password" the preceding text (for example "text4") is always the same (the same for the accompanying "access user")
=> the exact text-prefixes I don't know at the time of the shell script run (I know only that they are the same for a belonging together pair of user-password; otherwise I could go there with an exaxt grep on the prefix text and split afterwards with awk -F\= .... )
=> of course there could be also more lines than these examples; so I have to search what pairs are belonging together, according to the prefix text, but how ?
=> the lines could also stand disordered
=> So as an OUTPUT FILE I would need only the belonging together
user<blank>password pairs regardless if it is admin or access user, must also not be "ordered" necessarily, but with the belonging together user/password pairs:
Hans Dampf
Klaus Krampf
....
sack mack
For me (still the algorithmic difficulty is, that I don't want to bring mistakenly
for example the "text3.access.user" with the "text1.access.password" together, but the pairs with the same text prefix
Now I hope, that I did not describe my problem to extensive and that it can be understood.
For a quick help I would be very thankful
Thank you both first of all, I really appreciate people here: but the problem I described is a bit harsher here:
The "text" prefix can contain "." characters also for example: "dsds.fdfdf.sgdsg" and it is definitely like this, so I cannot say the whole string can be divided by three sub-strings separated by "." So I think one has to search explicitly for the patterns for example "admin.user" and compare the text in front to retrieve the correct user/password combination .... Hmm ?
the more complex realistic data sample could be (instaed of the "textx"
aa.bbb.ccc.admin.user=Hans aa.bbb.ccc.admin.password=Dampf aa.bbb.ccc.access.user=Klaus aa.bbb.ccc.access.password=Krampf gggg.hh.zzz.tttt.admin.user=Willi
gggg.hh.zzz.tttt.admin.password=stumpf gggg.hh.zzz.tttt.access.user=heiner gggg.hh.zzz.tttt.access.password=keiner
# and so on: "textx" is a substring with a variable number of substrings
# delimited by ".", but is each the same for the user/password pair
# belonging together
Base on original data sample using only bash shell
while read line;do line="${line/${line%.*.*}/}";a=( ${line//[.=]/ } );case ${a[1]} in user) b[${a[0]}]=${a[2]};;password)echo ${b[${a[0]}]} ${a[2]};;*);;esac;done <file
Hans Dampf
Klaus Krampf
Willi stumpf
heiner keiner
reiner nocheiner
thomas owas
kalli malli
sack mack
My solution missed a requirement:
=> for a belonging together pair for example "admin.user/admin.password" the preceding text (for example "text4") is always the same (the same for the accompanying "access user")