usage of Awk command for output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting usage of Awk command for output
# 8  
Old 10-05-2012
Again, have you tried the sed command?
Try it on both the input samples and check.
The awk command will need some more change when the number of words in the OLD and NEW lines exceeds 3. As the requirement (as far as I can understand) is to remove the OLD and NEW tags along with the pound signs, the awk script should have been written using sub function.

Last edited by elixir_sinari; 10-05-2012 at 07:37 AM..
# 9  
Old 10-05-2012
just need to do small change...
Code:
awk -F "[# ]" 'NF == 1{print}
/NEW#/{s=$2" "$3}
/OLD#/{print $2" "$3,s}' OFS=" --> " file

# 10  
Old 10-05-2012
With small corrections (remove anchoring & multiple spaces), elixir_sinari's proposal should work:
Code:
$ sed '/NEW#/ {s///;h;d}; /OLD#/ {s///;G;s/\n/ -->/;s/  */ /g}' file
CH_PPV_AUDIT_DISTRIBUTOR
 EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc1 --> EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc2
CH_PPV_AUDIT_ENCODER
 UPC_CFG_CH_PPV_AUDIT_ENCODER 1.0.2. --> UPC_CFG_AUDIT_REJECTED_ENCODER 1.1.0.
$

Pamu's suggestion needs a "+" after the -F"[# ]" 'cos there's many spaces out there, and needs to use $3 and $4 for output.
# 11  
Old 10-05-2012
Hi,

Thanks all for your effort. Let me just put what exactly i am looking for;
I have attached an input file and here what i do from it;

Code:
cat -vt diffStreamVersions.txt |sed 's/SQL>//g' | sed 's/ //g' | tr ':' '\n' |tr '-' '\t' | tr '|' '\t' | sort -n |
/usr/local/bin/gawk -F";" '{OFS="\t";if(x!=$1){print "\n"$1;x=$1};print "\t"$3}'

Output is as follows;
Code:
CH_PPV_AUDIT_DISTRIBUTOR
NEW#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc2
OLD#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc1
NEW!BehaviourOnError Abort
NEW!OutputFileNameExtractionMask
NEW!Subdirectory
NEW!TargetDirectory ${EventLinkUserHome}/delivery/UPC_PE_Rejected_Loader_stream/INPUT/${Affiliate}_PPV
NEW!TempDirectory ${EventLinkUserHome}/delivery/UPC_PE_Rejected_Loader_stream/INPUT/${Affiliate}_PPV/temp
OLD!BehaviourOnError Restart
OLD!TargetDirectory ${EventLinkUserHome}/delivery/UPC_PE_Rejected_Loader_stream/INPUT/CH_PPV
OLD!TempDirectory ${EventLinkUserHome}/delivery/UPC_PE_Rejected_Loader_stream/INPUT/CH_PPV/temp
CH_PPV_AUDIT_ENCODER
NEW#UPC_CFG_AUDIT_REJECTED_ENCODER 1.1.0.
OLD#UPC_CFG_CH_PPV_AUDIT_ENCODER 1.0.2.
NEW!OutputDescriptionFileName vod.xml
OLD!OutputDescriptionFileName audit_file_description.xml
NEW?AUDIT_REJECTED 0
NEW?RDC_AUDIT_OUT 0
OLD?AUDIT_REJECTED 0
OLD?RDC_AUDIT_OUT 0
OLD?VALIDATION_AUDIT_OUT 0
NEW@UPC_CFG_AUDIT_REJECTED_ENCODER REJ
OLD@UPC_CFG_CH_PPV_AUDIT_ENCODER REJ
CH_PPV_BACKUP
NEW#UPC_CFG_BACKUP 1.2.1.
NEWNODE
NEW#EL_APP_FTP_DISTRIBUTOR 2.1.4.upc1
NEW#EL_LIB_SFTP 1.1.0.
NEW!BehaviourOnError Abort
NEW!BlockSize
NEW!Cipher
NEW!Compression
NEW!CompressionMethod gzip
NEW!ConnectionEstablishmentTimeout
NEW!ConnectionRetryCount
NEW!ConnectionRetryInterval
NEW!DailyDirectories no
NEW!DestinationHost
NEW!ExternalCommand
NEW!FlagFileSuffix
NEW!InputLinkDirectories Yes
NEW!InputLinksToSubDirectories CAS_COLLECTOR=RAW/&SOURCEID,COLLECTED=RAW/&SOURCEID
NEW!Kex
NEW!MaxDays 0
NEW!MaxFiles 0
NEW!MaximumReconnectionInterval
NEW!MaximumSustainedNetworkDowntime
NEW!OriginalFilenameMask
NEW!Password
NEW!Port
NEW!PrivateKey
NEW!PublicKey
NEW!RemoteOS
NEW!RemotePrefix
NEW!RemoteSuffix
NEW!Ruleset backup.pm
NEW!SourceIdDirectories no
NEW!TargetDirectory /backup/BACKUP_EL603/${StreamName}
NEW!TempDirectory
NEW!TempSuffix
NEW!TransferMode
NEW!TransferProtocol Local
NEW!TransferRetryCount
NEW!TransferRetryInterval
NEW!TransferType
NEW!Username
NEW?CAS_COLLECTOR 1
NEW?COLLECTED 1
NEW?ENCODED_AUDIT 1
NEW?ENCODED_DWH 1
NEW?ENCODED_KENAN 1
CH_PPV_CAS_COLLECTOR
NEW#UPC_CFG_CAS_COLLECTOR 2.1.0.
OLD#UPC_CFG_CAS_COLLECTOR 2.0.0.
NEW#UPC_APP_CAS_COLLECTOR 2.3.0.
OLD#UPC_APP_CAS_COLLECTOR 2.2.4.
NEW!BindTimeout 10s
NEW!CasHeartbeatInterval 5m
NEW!CloseFilesAtSchedule 0
NEW!CommitInterval 10s
NEW!MaxAgeOfFile 30m
NEW!NoDataTimeout 12h
NEW!OutputFileNameCreationMask ${Affiliate}CAS_&CREATIONTIME(%Y%m%d%H%M%S)
NEW!RecordLimit 10000
NEW!RestartInterval 1d
NEW!TransactionIdFile ${EventLinkUserHome}/delivery/${StreamName}/WORKING/id_file.txt
OLD!BindTimeout 10
OLD!CasHeartbeatInterval 300
OLD!CommitInterval 10
OLD!OutputFileNameCreationMask CHCAS_&CREATIONTIME(%Y%m%d%H%M%S)
OLD!TransactionIdFile ${EventLinkUserHome}/delivery/UPCCH_PPV/WORKING/id_file.txt
CH_PPV_DECODER
NEW#UPC_CFG_CAS_DECODER 1.0.0.
OLD#UPC_CFG_CH_PPV_CAS_DECODER 1.0.0.
NEW#EL_APP_ASCII_DECODER 3.0.3.upc5
OLD#EL_APP_MDS_ARM_FR_DECODER 1.1.5.
NEW!AuditFiltered 1
NEW!CSVFieldsContainDelimiters 0
NEW!DiscardEmptyFiles 0
NEW!DiscardOnRejection 0
NEW!EscapeWithBackslash 0
NEW!HeaderIdentifier
NEW!InputDescription cas.desc
NEW!InvalidLink INVALID
NEW!OutputLink DECODED
NEW!PercentOfRejectedRecordsAllowed
NEW!RecordIdentifier
NEW!RejectInvalid 0
NEW!SendInvalid 1
NEW!TrailerIdentifier
OLD!DiscardFailureThreshold 15
OLD!NetworkElementID CAS
OLD!SendDiscardedFilesToLink
OLD!UseRecordSequenceNumbers
NEW?DECODED 0
NEW?INVALID 0
OLD?DECODED_CAS 0
CH_PPV_DWH_DISTRIBUTOR
NEW#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc2
OLD#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc1
NEW!CompressionMethod compress
NEW!OutputFileNameExtractionMask CDR\.(.+)
NEW!Password
NEW!PrivateKey ${EventLinkUserHome}/.ssh/id_rsa
NEW!PublicKey ${EventLinkUserHome}/.ssh/id_rsa.pub
NEW!Subdirectory UPC${Affiliate}_$1
NEW!TargetDirectory ${EventLinkUserHome}/delivery/${StreamName}/OUTPUT/DWH
NEW!Username ${EventLinkUser}
OLD!CompressionMethod nocompression
OLD!Password u1elkpe
OLD!PrivateKey
OLD!PublicKey
OLD!TargetDirectory ${EventLinkUserHome}/delivery/UPCCH_PPV/OUTPUT/DWH
OLD!Username u1elkpe
CH_PPV_DWH_ENCODER
NEW#UPC_CFG_CAS_DWH_ENCODER 1.1.0.
OLD#UPC_CFG_CH_PPV_BRIO_ENCODER 1.1.0.
NEW!CreateEmptyOutputFileOnFlush 0
NEW!CreateEmptyOutputFileOnSeparation 0
NEW!CreateEmptyOutputFiles 0
NEW!MaxAgeOfFile
NEW!OutputDescriptionFileName output_description.xml
OLD!CreateEmptyOutputFileOnFlush
OLD!CreateEmptyOutputFileOnSeparation
OLD!CreateEmptyOutputFiles
OLD!MaxAgeOfFile 1M
OLD!OutputDescriptionFileName brio_description.xml
NEW@UPC_CFG_CAS_DWH_ENCODER REJ
OLD@UPC_CFG_CH_PPV_BRIO_ENCODER REJ
CH_PPV_FRAUD_DISTRIBUTOR
NEW#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc2
OLD#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc1
NEW!OutputFileNameExtractionMask
NEW!Password
NEW!PrivateKey ${EventLinkUserHome}/.ssh/id_rsa
NEW!PublicKey ${EventLinkUserHome}/.ssh/id_rsa.pub
NEW!Subdirectory
NEW!TargetDirectory ${EventLinkUserHome}/delivery/${StreamName}/OUTPUT/FRAUD
NEW!TempDirectory ${EventLinkUserHome}/delivery/${StreamName}/OUTPUT/FRAUD/tmp
NEW!Username ${EventLinkUser}
OLD!Password u1elkpe
OLD!PrivateKey
OLD!PublicKey
OLD!TargetDirectory ${EventLinkUserHome}/delivery/UPCCH_PPV/OUTPUT/FRAUD
OLD!TempDirectory ${EventLinkUserHome}/delivery/UPCCH_PPV/OUTPUT/FRAUD/tmp
OLD!Username u1elkpe
CH_PPV_HORIZON_BLN
NEW#UPC_CFG_HORIZON_BLN 1.5.2.
OLD#UPC_CFG_HORIZON_BLN 1.5.1.
NEW#UPC_LIB_PERL_UTILS 3.1.2.
OLD#UPC_LIB_PERL_UTILS 3.1.0.
NEW!KenanCounter K_0_1_2
NEW!OracleDatabaseName ${EventLinkDatabase}
OLD!AuditOutType ${AuditOutType}
OLD!KenanCounter K_0_2_1
OLD!OracleDatabaseName U1ELKPE
OLD!StreamName ${StreamName}
CH_PPV_KENAN_DISTRIBUTOR
NEW#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc2
OLD#EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc1
NEW!OutputFileNameExtractionMask
NEW!Subdirectory
NEW!TargetDirectory ${EventLinkUserHome}/delivery/${StreamName}/OUTPUT/KENAN
NEW!Username ${EventLinkUser}
OLD!TargetDirectory ${EventLinkUserHome}/delivery/UPCCH_PPV/OUTPUT/KENAN
OLD!Username u1elkpe
CH_PPV_KENAN_DWH_BLN
NEW#UPC_CFG_CH_PPV_KENAN_BRIO_BLN 2.0.0.
OLD#UPC_CFG_CH_PPV_KENAN_BRIO_BLN 1.0.5.
NEW#UPC_LIB_PERL_UTILS 3.1.2.
OLD#UPC_LIB_PERL_UTILS 1.11.2.
NEW!ReprocessLimit 100d
OLD!202_DEFAULT_TIME 000000
OLD!AuditOutType ${AuditOutType}
OLD!LsAdmin ${EventLinkUserHome}/EventLink/lookup_server3/bin/ls_admin
OLD!ReprocessLimit 100
OLD!StreamName ${StreamName}
NEW?RDC_OUT1 0
OLD?RDC_OUT 0
OLD@UPC_CFG_CH_PPV_KENAN_BRIO_BLN INVALID_TVOD
OLD@UPC_CFG_CH_PPV_KENAN_BRIO_BLN REJECTED
CH_PPV_KENAN_ENCODER
NEW#UPC_CFG_CAS_KENAN_ENCODER 1.1.0.
OLD#UPC_CFG_CH_PPV_KENAN_ENCODER 1.0.0.
NEW#EL_LIB_CML 1.5.5.
OLD#EL_LIB_CML 1.5.4.
NEW!CreateEmptyOutputFileOnFlush 0
NEW!CreateEmptyOutputFileOnSeparation 0
NEW!CreateEmptyOutputFiles 0
NEW!DataRecordType PV1
NEW!MaxAgeOfFile
NEW!OutputDescriptionFileName dpv_old.xml
NEW!OutputFileNameCreationMask PV1.&SEQ(7).&CREATIONTIME(%Y%m%d%H%M%S).&SOURCEID.00.&MIN(EL_PURCHASE_DATETIME) &MAX(EL_PURCHASE_DATETIME)
NEW!RecordLimit
NEW!SeparateSequenceNumbersInOutput 0
OLD!CreateEmptyOutputFileOnFlush
OLD!CreateEmptyOutputFileOnSeparation
OLD!CreateEmptyOutputFiles
OLD!MaxAgeOfFile 86400
OLD!OutputDescriptionFileName kenan_description.xml
OLD!OutputFileNameCreationMask PV1.&SEQ(7).&CREATIONTIME(%Y%m%d%H%M%S).&SOURCEID.00.&MIN(EL_PURCHASE_LOCALTIME) &MAX(EL_PURCHASE_LOCALTIME2)
OLD!RecordLimit 100
OLD!SeparateSequenceNumbersInOutput 1
NEW@UPC_CFG_CAS_KENAN_ENCODER REJ
OLD@UPC_CFG_CH_PPV_KENAN_ENCODER REJ
CH_PPV_LOCAL_COLLECTOR
NEW#EL_APP_FTP_COLLECTOR 2.1.4.upc3
OLD#EL_APP_FTP_COLLECTOR 2.1.4.upc1
NEW#EL_LIB_NODE_EXTENSIONS 1.1.1.
NEW#UPC_LIB_PERL_UTILS 1.11.2.
NEW!BehaviourOnError Abort
NEW!OnlyCollectFilesOlderThan
NEW!SourceDirectory ${EventLinkUserHome}/delivery/${StreamName}/INPUT/
OLD!BehaviourOnError Restart
OLD!SourceDirectory ${EventLinkUserHome}/delivery/UPCCH_PPV/INPUT/
CH_PPV_OUTPUT_BACKUP
DONOTEXISTANYMORE
OLD#UPC_CFG_BACKUP 1.1.1.
OLD#EL_APP_FTP_DISTRIBUTOR 2.1.4.upc1
OLD#EL_LIB_SFTP 1.1.0.
OLD!BehaviourOnError Restart
OLD!BlockSize
OLD!Cipher
OLD!Compression
OLD!CompressionMethod gzip
OLD!ConnectionEstablishmentTimeout
OLD!ConnectionRetryCount
OLD!ConnectionRetryInterval
OLD!DailyDirectories no
OLD!DestinationHost
OLD!ExternalCommand
OLD!FlagFileSuffix
OLD!InputLinkDirectories Yes
OLD!Kex
OLD!MaxDays 30
OLD!MaxFiles 0
OLD!MaximumReconnectionInterval
OLD!MaximumSustainedNetworkDowntime
OLD!OriginalFilenameMask
OLD!Password
OLD!Port
OLD!PrivateKey
OLD!PublicKey
OLD!RemoteOS
OLD!RemotePrefix
OLD!RemoteSuffix
OLD!Ruleset backup.pm
OLD!SourceIdDirectories no
OLD!TargetDirectory /backup/BACKUP_EL603/UPCCH_PPV
OLD!TempDirectory
OLD!TempSuffix
OLD!TransferMode
OLD!TransferProtocol Local
OLD!TransferRetryCount
OLD!TransferRetryInterval
OLD!TransferType
OLD!Username
OLD?ENCODED_AUDIT 1
OLD?ENCODED_DWH 1
OLD?ENCODED_KENAN 1
CH_PPV_PRODIS_COLLECTOR
NEW!DeleteSource No
NEW!RemotePrefix old_
NEW!SourceDirectory ${EventLinkUserHome}/delivery/${StreamName}/INPUT/PRODIS
NEW!Username ${EventLinkUser}
OLD!DeleteSource Yes
OLD!RemotePrefix
OLD!SourceDirectory ${EventLinkUserHome}/delivery/UPCCH_PPV/INPUT/PRODIS
OLD!Username u1elkpe
CH_PPV_PRODIS_COMMON_BLN
NEW#UPC_CFG_PRODIS_COMMON_BLN 1.2.1.
OLD#UPC_CFG_PRODIS_COMMON_BLN 1.2.0.
NEW#UPC_LIB_PERL_UTILS 3.1.2.
OLD#UPC_LIB_PERL_UTILS 2.0.0.
OLD!AuditOutType ${AuditOutType}
OLD!StreamName ${StreamName}
CH_PPV_PRODIS_DECODER
NEW#EL_APP_ASCII_DECODER 3.0.3.upc5
OLD#EL_APP_ASCII_DECODER 3.0.3.upc4
NEW!PercentOfRejectedRecordsAllowed
CH_PPV_PRODIS_FDC
NEW!SequenceChecking 0
NEW!TRS.DataStorage ${StreamName}
OLD!SequenceChecking 1
OLD!TRS.DataStorage UPCCH_PPV
CH_PPV_PRODIS_RDC
NEW#UPC_CFG_RECORD_CHECKER 8.2.0.
OLD#UPC_CFG_RECORD_CHECKER 8.1.0.
NEW#UPC_LIB_PERL_UTILS 3.1.2.
OLD#UPC_LIB_PERL_UTILS 2.0.0.
NEW!DuplicateCheckEnabled No
NEW!OutputCounter B_0_1_2
NEW!RestartInterval 1d
NEW!TRS.DataStorage ${StreamName}
OLD!DuplicateCheckEnabled Yes
OLD!NodeName CH_PPV_PRODIS_RDC
OLD!OutputCounter B_0_2_1
OLD!StreamName ${StreamName}
OLD!TRS.DataStorage UPCCH_PPV
NEW@UPC_CFG_RECORD_CHECKER INVALID_DATA
CH_PPV_RAW_BACKUP
DONOTEXISTANYMORE
OLD#UPC_CFG_BACKUP 1.1.1.
OLD#EL_APP_FTP_DISTRIBUTOR 2.1.4.upc1
OLD#EL_LIB_SFTP 1.1.0.
OLD!BehaviourOnError Restart
OLD!BlockSize
OLD!Cipher
OLD!Compression
OLD!CompressionMethod gzip
OLD!ConnectionEstablishmentTimeout
OLD!ConnectionRetryCount
OLD!ConnectionRetryInterval
OLD!DailyDirectories no
OLD!DestinationHost
OLD!ExternalCommand
OLD!FlagFileSuffix
OLD!InputLinkDirectories No
OLD!Kex
OLD!MaxDays 30
OLD!MaxFiles 0
OLD!MaximumReconnectionInterval
OLD!MaximumSustainedNetworkDowntime
OLD!OriginalFilenameMask
OLD!Password
OLD!Port
OLD!PrivateKey
OLD!PublicKey
OLD!RemoteOS
OLD!RemotePrefix
OLD!RemoteSuffix .&CREATIONTIME(%Y%m%d%H%M%S)
OLD!Ruleset backup.pm
OLD!SourceIdDirectories yes
OLD!TargetDirectory /backup/BACKUP_EL603/UPCCH_PPV/RAW
OLD!TempDirectory
OLD!TempSuffix
OLD!TransferMode
OLD!TransferProtocol Local
OLD!TransferRetryCount
OLD!TransferRetryInterval
OLD!TransferType
OLD!Username
OLD?CAS_COLLECTOR 1
OLD?COLLECTED 1
CH_PPV_RDC
NEW#UPC_CFG_RECORD_CHECKER 8.2.0.
OLD#UPC_CFG_RECORD_CHECKER 7.1.5.
NEW#UPC_LIB_PERL_UTILS 3.1.2.
NEW!AuditFields AUD_UA=I_UA,AUD_STU_NUMBER=I_STU_NUMBER,AUD_IMS_PRODUCT_ID=I_IMS_PRODUCT_ID
NEW!DuplicateCheckEnabled No
NEW!DuplicateCounter P_0_1_1
NEW!DuplicateDurationCounter
NEW!DurationField
NEW!InputCounter
NEW!InputDurationCounter
NEW!Keys I_UA,I_IMS_PRODUCT_ID
NEW!OutputCounter
NEW!OutputDurationCounter
NEW!RestartInterval 1d
NEW!SeparationCondition
NEW!SeparationValue1
NEW!SeparationValue2
NEW!SeparationValue3
NEW!SeparationValue4
NEW!SeparationValue5
NEW!TRS.DataStorage ${StreamName}
OLD!DuplicateCheckEnabled Yes
OLD!Keys I_UA,I_PURCHASE_DATE,I_PURCHASE_TIME,I_IMS_PRODUCT_ID
OLD!StreamName ${StreamName}
OLD!TRS.DataStorage UPCCH_PPV
NEW?RDC_OUT1 0
NEW?RDC_OUT2 0
NEW?RDC_OUT3 0
NEW?RDC_OUT4 0
NEW?RDC_OUT5 0
NEW?VALID 0
OLD?RDC_OUT 0
OLD?VALIDATION_OUT 0
NEW@UPC_CFG_RECORD_CHECKER DUPLICATE_RECORDS
NEW@UPC_CFG_RECORD_CHECKER INVALID_DATA
OLD@UPC_CFG_RECORD_CHECKER PV_INVALID_DATA
CH_PPV_VALIDATOR
NEW#UPC_CFG_CAS_VALIDATOR 1.1.1.
OLD#UPC_CFG_VOD_VALIDATOR 1.1.1.
NEW#UPC_LIB_PERL_UTILS 3.1.2.
NEW!InputCounter I_0_2_1
NEW!RejectedCounter P_0_1_1
NEW!RestartInterval 1d
NEW!Timezone ${Timezone}
OLD!AuditOutType ${AuditOutType}
OLD!StreamName ${StreamName}
NEW?AUDIT_REJECTED 0
NEW?DECODED 0
NEW?INVALID 0
NEW?VALID 0
OLD?DECODED_CAS 0
OLD?VALIDATION_AUDIT_OUT 0
OLD?VALIDATION_OUT 0
NEW@UPC_CFG_CAS_VALIDATOR INVALID_DATA
OLD@UPC_CFG_VOD_VALIDATOR INVALID_DATETIME



The script I want to show output as comparisons between the two same types of records;
NOTE: NEW#,OLD#,NEW!,OLD!,NEW?,OLD?,NEW@,OLD@ are my own defined ways to differentiate between the different types of outputs.

<Name>
<TechnicalName><TAB><OldValue><TAB><NewValue>



Also there are cases in which only NEW is present and OLD is not there leave compared value of OLD as NULL and vicaversa.


I hope i made the complete problem understood. I real;ly need your help as i have been stuck with this for long.

Thanks Again for your patience.

Last edited by Scrutinizer; 10-08-2012 at 12:43 PM.. Reason: code tags
# 12  
Old 10-05-2012
Code:
awk -F "[# \!\?\@]" '{if($0~ /^NEW/){if(NF > 2){a[$2]=$2" "$3}else{print $2}}else if ($0 ~ /^OLD/){print $2" "$3,a[$2]}else{print}}' OFS=" --> " file

Hope this helps youSmilie

Last edited by pamu; 10-05-2012 at 11:16 PM.. Reason: corrected....
# 13  
Old 10-05-2012
Does this give you what you want (from your original file)? If it does, format the output as per your requirement.
Code:
gawk -F: '{for(i=1;i<NF;i++)
{
 n=split($i,e,/[-;|]/)
 exists[e[1]]
 if(sub(/^OLD./,"",e[3]))
 {
  oldval[e[1],e[2],e[3]]=(e[4]~/^[[:blank:]]*$/?SUBSEP:e[4])
  newval[e[1],e[2],e[3]]
 }
 else if(sub(/^NEW./,"",e[3]))
 {
  newval[e[1],e[2],e[3]]=e[4]
  oldval[e[1],e[2],e[3]]
 }
}}
END{
no_of_names=asorti(exists)
for(i=1;i<=no_of_names;i++)
{
 print exists[i]
 for(j in oldval)
 {
  split(j,temp,SUBSEP)
  if(temp[1]==exists[i])
   print temp[3],(length(oldval[j])?(oldval[j]==SUBSEP?" ":oldval[j]):"NULL"),newval[j]|"sort"
 }
 close("sort")
 printf "\n"
}
}' OFS='|' diffStreamVersions.txt


Last edited by elixir_sinari; 10-08-2012 at 01:12 PM..
This User Gave Thanks to elixir_sinari For This Post:
# 14  
Old 10-05-2012
Hi,

Thanks for the query. It seems to work but there are some small small correction required. If you can help me with then then it would be of great use.

The script generate almost corrrect output but please refer to below output:

Code:
CH_PPV_AUDIT_DISTRIBUTOR
BehaviourOnError|Restart|Abort
EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc1||
EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc2||
OutputFileNameExtractionMask||
Subdirectory||
TargetDirectory|${EventLinkUserHome}/delivery/UPC_PE_Rejected_Loader_stream/INPUT/CH_PPV|${EventLinkUserHome}/delivery/UPC_PE_Rejected_Loader_stream/INPUT/${Affiliate}_PPV
TempDirectory|${EventLinkUserHome}/delivery/UPC_PE_Rejected_Loader_stream/INPUT/CH_PPV/temp|${EventLinkUserHome}/delivery/UPC_PE_Rejected_Loader_stream/INPUT/${Affiliate}_PPV/temp

in input data:
Code:
CH_PPV_DWH_ENCODER;A;OLD#UPC_CFG_CH_PPV_BRIO_ENCODER-1.1.0.:CH_PPV_DWH_DISTRIBUTOR;A;OLD#EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc1:CH_PPV_KENAN_DISTRIBUTOR;A;OLD#EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc1:CH_PPV_AUDIT_DISTRIBUTOR;A;NEW#EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc2:CH_PPV_AUDIT_ENCODER;A;NEW#UPC_CFG_AUDIT_REJECTED_ENCODER-1.1.0.:CH_PPV_HORIZON_BLN;A;NEW#UPC_CFG_HORIZON_BLN-1.5.2.:CH_PPV_DWH_ENCODER;A;NEW#UPC_CFG_CAS_DWH_ENCODER-1.1.0.:CH_PPV_DECODER;A;NEW#UPC_CFG_CAS_DECODER-1.0.0.:CH_PPV_KENAN_DWH_BLN;A;OLD#UPC_CFG_CH_PPV_KENAN_BRIO_BLN-1.0.5.:CH_PPV_RAW_BACKUP;A;OLD#UPC_CFG_BACKUP-1.1.1.:CH_PPV_PRODIS_RDC;A;OLD#UPC_CFG_RECORD_CHECKER-8.1.0.:CH_PPV_KENAN_DWH_BLN;A;NEW#UPC_CFG_CH_PPV_KENAN_BRIO_BLN-2.0.0.:CH_PPV_PRODIS_COMMON_BLN;A;NEW#UPC_CFG_PRODIS_COMMON_BLN-1.2.1.:CH_PPV_VALIDATOR;A;NEW#UPC_CFG_CAS_VALIDATOR-1.1.1.:CH_PPV_CAS_COLLECTOR;A;OLD#UPC_CFG_CAS_COLLECTOR-2.0.0.:CH_PPV_PRODIS_COMMON_BLN;A;OLD#UPC_CFG_PRODIS_COMMON_BLN-1.2.0.:CH_PPV_DECODER;A;OLD#UPC_CFG_CH_PPV_CAS_DECODER-1.0.0.:CH_PPV_RDC;A;NEW#UPC_CFG_RECORD_CHECKER-8.2.0.:CH_PPV_AUDIT_DISTRIBUTOR;A;OLD#EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc1:CH_PPV_RDC;A;OLD#UPC_CFG_RECORD_CHECKER-7.1.5.:CH_PPV_HORIZON_BLN;A;OLD#UPC_CFG_HORIZON_BLN-1.5.1.:CH_PPV_BACKUP;A;NEW#UPC_CFG_BACKUP-1.2.1.:CH_PPV_DWH_DISTRIBUTOR;A;NEW#EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc2:CH_PPV_OUTPUT_BACKUP;A;OLD#UPC_CFG_BACKUP-1.1.1.:CH_PPV_KENAN_ENCODER;A;OLD#UPC_CFG_CH_PPV_KENAN_ENCODER-1.0.0.:CH_PPV_FRAUD_DISTRIBUTOR;A;OLD#EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc1:CH_PPV_CAS_COLLECTOR;A;NEW#UPC_CFG_CAS_COLLECTOR-2.1.0.:CH_PPV_FRAUD_DISTRIBUTOR;A;NEW#EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc2:CH_PPV_AUDIT_ENCODER;A;OLD#UPC_CFG_CH_PPV_AUDIT_ENCODER-1.0.2.:CH_PPV_VALIDATOR;A;OLD#UPC_CFG_VOD_VALIDATOR-1.1.1.:CH_PPV_PRODIS_RDC;A;NEW#UPC_CFG_RECORD_CHECKER-8.2.0.:CH_PPV_KENAN_DISTRIBUTOR;A;NEW#EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc2:CH_PPV_KENAN_ENCODER;A;NEW#UPC_CFG_CAS_KENAN_ENCODER-1.1.0.:

the expected output was:
Code:
EL_CFG_FTP_DISTRIBUTOR-2.1.0.upc1|2.1.0.upc2|


Also if the OLD field is not exist i need to populate NULL
AND if OLD field exist and is blank then " "

Can you please check this. Really thanks a lot for putting soo much effort. Its really appreciated. I would never come up with such a script.

Last edited by Scrutinizer; 10-08-2012 at 12:42 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

No output from awk command

Hi all, In my SunOS 5.10, the command awk using BEGIN option doesn't print output variables like expected here is my test: with the following code everything is alright ps -eo pcpu,args | grep "httpd" | awk ' { print $1 } ' the result is 0.1 However, with this command ps -eo... (3 Replies)
Discussion started by: Elmassimo
3 Replies

2. Shell Programming and Scripting

Grep output to awk command

Hi Team(Solaris 5.8/Ksh), How can we save grep output to awk variable when grep returns more than one line or word. abc.log # more abc.log Hi Makarand How r u bye Makarand Hello when grep returns only 1 word below command works nawk -v var=`cat abc.log |grep "Hello"` 'BEGIN { if... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

3. How to Post in the The UNIX and Linux Forums

Usage of tail command in .awk

Hi, I want to do file format using awk script, for that i wan to use 'tail'. Here is the scenario. I will be having set of files in a directory. Those files i need to write to another directory with same file name, but while writing the file to out directory, i need to write the last line as... (3 Replies)
Discussion started by: Venkata Madhu
3 Replies

4. Shell Programming and Scripting

Format output in AWK command

hi Friends , I have a file as below s.txt 1~2~~4 2~6~~7 3~8~~9 t.txt 1~2~~4 2~5~8~7 3~8~~7 header for both files is common (2 Replies)
Discussion started by: i150371485
2 Replies

5. Shell Programming and Scripting

usage of AWK command under perl script

i have two files as shown below t1.txt: argument1 argu2 argu37 t2.txt: 22 33 44 i want o/p as argument1 22 argu2 33 argu37 44 i am trying to merge two file under perl script using following system("paste t1.txt t2.txt | awk... (3 Replies)
Discussion started by: roopa
3 Replies

6. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

7. Emergency UNIX and Linux Support

getting wrong output with AWK command!!!

i have a file which gets appended with 9 records daily and the file keeps growing from then...i use to store the previous day files count in a variable called oldfilecount and current files count as newfilecount.my requirement is that i need to start processing only the new records from the... (3 Replies)
Discussion started by: ganesh_248
3 Replies

8. Shell Programming and Scripting

Format Output with AWK command

Hi - I have a file with contents as below. 12.1 a.txt 12.1 b.txt 12.1 c.txt 13.2 a.txt 13.2 d.txt 14.3 f.txt 15.4 a.txt 15.4 b.txt 15.4 z.txt I need to print the contents like this. 12.1 a.txt <&nbsp><&nbsp><&nbsp>b.txt <&nbsp><&nbsp><&nbsp>c.txt (7 Replies)
Discussion started by: guruparan18
7 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. Shell Programming and Scripting

awk and grep command usage

hi Can anyone explain me how these two commands awk and grep works in a ksh shell Thanks Babu (1 Reply)
Discussion started by: ksmbabu
1 Replies
Login or Register to Ask a Question