usage of Awk command for output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting usage of Awk command for output
# 15  
Old 10-05-2012
I've made slight modifications in the script in my earlier post. Try now.
# 16  
Old 10-08-2012
Hi,

Thanks worked like a cream. Just one more thing i need to incorportae if you can tell me how to do it then my whole purpoose is solved.

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


For E.G:

Code:
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

Current Output :
Code:
AuditFields||AUD_UA=I_UA, AUD_STU_NUMBER=I_STU_NUMBER, AUD_IMS_PRODUCT_ID=I_IMS_PRODUCT_ID
DuplicateCheckEnabled|Yes|No
DuplicateCounter||P_0_1_1
DuplicateDurationCounter||
DurationField||
InputCounter||
InputDurationCounter||
Keys|I_UA, I_PURCHASE_DATE, I_PURCHASE_TIME, I_IMS_PRODUCT_ID|I_UA, I_IMS_PRODUCT_ID
OutputCounter||
OutputDurationCounter||
RDC_OUT1||0
RDC_OUT2||0
RDC_OUT3||0
RDC_OUT4||0
RDC_OUT5||0
RDC_OUT|0|
RestartInterval||1d
SeparationCondition||
SeparationValue1||
SeparationValue2||
SeparationValue3||
SeparationValue4||
SeparationValue5||
StreamName|${StreamName}|
TRS.DataStorage|UPCCH_PPV|${StreamName}


Expected Output:
Code:
DuplicateCounter||P_0_1_1
SeparationValue1|NULL|
SeparationValue2|NULL|
SeparationValue3|NULL|
SeparationValue4|NULL|
SeparationValue5|NULL|

DuplicateCounter Value was present but was blank hence blank.

SperationValue is only new. Thats why OLD as NULL.

Thanks a lot for your help!!!!

---------- Post updated at 07:15 AM ---------- Previous update was at 03:24 AM ----------

Hi,

Can you please just help me out with a small modification as expected above.

Regards
Rajan

---------- Post updated at 09:39 AM ---------- Previous update was at 07:15 AM ----------

Hi Everyone,

Kindly help me in finding a way out of it.

Thanks
Rajan

Moderator's Comments:
Mod Comment Bumping is not allowed

Last edited by Scrutinizer; 10-08-2012 at 12:40 PM..
# 17  
Old 10-08-2012
try with this..

Code:
awk -F "[# \!\?\@]" '{if($0~ /^NEW/){if(NF > 2){a[$2]=$2" "$3}else{print $2,"NULL"}}
else if ($0 ~ /^OLD/){print $2" "$3,a[$2];delet a[$2]}else{print}}END{for(i in a){ print a[i]}}' OFS="|" file


Last edited by pamu; 10-08-2012 at 11:51 AM.. Reason: corrected..
# 18  
Old 10-08-2012
Hi,

This doesnot work. I just need a small correction in the awk published by elixir_sinari. Can you please try.
Error generated:
Code:
awk: cmd. line:2: fatal: cannot open file `file' for reading (No such file or directory)

Code:
[u1elkpe@ /u01/appl/u1elkpe/Rajan$]> awk -F "[# \!\?\@]" '{if($0~ /^NEW/){if(NF > 2){a[$2]=$2" "$3}else{print $2,"NULL"}}
else if ($0 ~ /^OLD/){print $2" "$3,a[$2];delet a[$2]}else{print}}END{for(i in a){ print a[i]}}' OFS="|" diffStreamVersions.txt
awk: warning: escape sequence `\!' treated as plain `!'
awk: warning: escape sequence `\?' treated as plain `?'
awk: warning: escape sequence `\@' treated as plain `@'


Thanks for your help anyway.

Regards
Rajan

Last edited by Scrutinizer; 10-08-2012 at 12:44 PM.. Reason: code tags
# 19  
Old 10-08-2012
Quote:
Originally Posted by rajangupta2387
awk: warning: escape sequence `\!' treated as plain `!'
awk: warning: escape sequence `\?' treated as plain `?'
awk: warning: escape sequence `\@' treated as plain `@'[/CODE]
these are not errors. just warnings.. ignore it...

Are getting the output right..?
# 20  
Old 10-08-2012
Hi,
have made some changes in the earlier code. Check now.
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