-2

source data

KKK-SNMImsi: 444444
KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile
KKK-SNMMmeAddress: TDSGSN01
KKK-SNMMsisdn: 44235682436
KKK-SNMLocationState: LOCATED
KKK-SNMRoamingAllowed: FALSE
KKK-SNMRoamingRestriction: TRUE
KKK-SNMOdb: NONE
KKK-SNMImsi: 444445
KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile
KKK-SNMMmeAddress: TDSGSN01
KKK-SNMMsisdn: 44235681280
KKK-SNMLocationState: LOCATED
KKK-SNMRoamingAllowed: FALSE
KKK-SNMRoamingRestriction: TRUE
KKK-SNMOdb: NONE
KKK-SNMImsi: 444447
KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile
KKK-SNMMmeAddress: TDSGSN01
KKK-SNMMsisdn: 44235681255
KKK-SNMLocationState: LOCATED
KKK-SNMRoamingAllowed: FALSE
KKK-SNMRoamingRestriction: TRUE
KKK-SNMOdb: NONE

Output target

KKK-SNMImsi: 444444,KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile,KKK-SNMMmeAddress: TDSGSN01,KKK-SNMMsisdn: 44235682436,KKK-SNMLocationState: LOCATED,KKK-SNMRoamingAllowed: FALSE,KKK-SNMRoamingRestriction: TRUE,KKK-SNMOdb: NONE
KKK-SNMImsi: 444445,KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile,KKK-SNMMmeAddress: TDSGSN01,KKK-SNMMsisdn: 44235681280,KKK-SNMLocationState: LOCATED,KKK-SNMRoamingAllowed: FALSE,KKK-SNMRoamingRestriction: TRUE,KKK-SNMOdb: NONE
KKK-SNMImsi: 444447,KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile,KKK-SNMMmeAddress: TDSGSN01,KKK-SNMMsisdn: 44235681255,KKK-SNMLocationState: LOCATED,KKK-SNMRoamingAllowed: FALSE,KKK-SNMRoamingRestriction: TRUE,KKK-SNMOdb: NONE

I used to run using below command and not working

egrep -R "HSS-EsmImsi:|HSS-EsmUserProfileId:|HSS-EsmMmeAddress:|HSS-EsmMsisdn:|HSS-EsmLocationState:|HSS-EsmRoamingAllowed:|HSS-EsmRoamingRestriction:|HSS-EsmOdb:" inputfile.ldif | paste - - - - - - - - - |column -t  >> outputfile.ldif
0

1 Answer 1

0

Using GNU awk for multi-char RS and RT:

$ awk -v RS='KKK-SNMOdb: NONE\n' -F'\n' -v OFS=',' '{ORS=RT; $1=$1; print}' file
KKK-SNMImsi: 444444,KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile,KKK-SNMMmeAddress: TDSGSN01,KKK-SNMMsisdn: 44235682436,KKK-SNMLocationState: LOCATED,KKK-SNMRoamingAllowed: FALSE,KKK-SNMRoamingRestriction: TRUE,KKK-SNMOdb: NONE
KKK-SNMImsi: 444445,KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile,KKK-SNMMmeAddress: TDSGSN01,KKK-SNMMsisdn: 44235681280,KKK-SNMLocationState: LOCATED,KKK-SNMRoamingAllowed: FALSE,KKK-SNMRoamingRestriction: TRUE,KKK-SNMOdb: NONE
KKK-SNMImsi: 444447,KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile,KKK-SNMMmeAddress: TDSGSN01,KKK-SNMMsisdn: 44235681255,KKK-SNMLocationState: LOCATED,KKK-SNMRoamingAllowed: FALSE,KKK-SNMRoamingRestriction: TRUE,KKK-SNMOdb: NONE

Here's what those constructs do:

  • -v = initialize an awk variable to a value.
  • -v RS='KKK-SNMOdb: NONE\n' = set the input Record Separator to that regexp (will behave as a literal string in this case since it contains no regexp metachars) so the input is treated as multi-line records ending with the matching string.
  • -F'\n' = set the input Field Separator to a newline so we can later convert those to commas. We could have used -v FS='\n' instead here, they're equivalent constructs.
  • -v OFS=',' = set the Output Field Separator to a comma so we can replace each newline with it before outputting the record.
  • ORS=RT = set the Output Record Separator to the value of RT which contains the string that matched the regexp stored in RS so when the record is printed later that string will terminate each output record/line.
  • $1=$1 = modify a field so the record is reconstructed replacing all FS values with OFS values, thereby changing the input multi-line record of newline-separated fields into a single line record of comma-separated fields.
  • print = print the current record.

Get the book Effective AWK Programming, 5th Edition, by Arnold Robbins to learn more about how to use awk. There are also plenty of google results available.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.