usage of Awk command for output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting usage of Awk command for output
# 1  
Old 10-05-2012
usage of Awk command for output

Hi Experts,

I have a Text file generated as below;
Code:
<NAME>
    NEW#<technicalName><TAB> <Version>
    OLD#<technicalName><TAB> <Version>

e.g.
Code:
CH_PPV_AUDIT_DISTRIBUTOR
        NEW#EL_CFG_FTP_DISTRIBUTOR      2.1.0.upc2
        OLD#EL_CFG_FTP_DISTRIBUTOR      2.1.0.upc1
CH_PPV_AUDIT_ENCODER
        NEW#UPC_CFG_AUDIT_REJECTED_ENCODER      1.1.0.
        OLD#UPC_CFG_CH_PPV_AUDIT_ENCODER        1.0.2.

I need to generate the output as follows
Code:
CH_PPV_AUDIT_DISTRIBUTOR
       EL_CFG_FTP_DISTRIBUTOR    2.1.0.upc1  -->   2.1.0.upc2
CH_PPV_AUDIT_ENCODER
        UPC_CFG_AUDIT_REJECTED_ENCODER      1.0.2. --> 1.1.0.
     
<NAME>
        <TechnicalNewName>    oldversion  -->   NewVersion

Kindly help me in generating such an output.

Thanks in Advance.

Regards
Rajan

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by radoulov; 10-05-2012 at 06:23 AM..
# 2  
Old 10-05-2012
try this...
Code:
awk -F "[# ]" '{if($0 ~/#/){s=$3;getline;print $2" "$3,s}else{print }}' OFS=" --> " file

# 3  
Old 10-05-2012
Please use code tags for code and data samples.
Code:
sed '/^NEW#/{;s///;h;d;}
/^OLD#/{;s///;G;s/\n/ --> /;}' file


Last edited by elixir_sinari; 10-05-2012 at 05:56 AM..
# 4  
Old 10-05-2012
Hi,

I used this awk command as below;
Code:
/usr/local/bin/gawk -F "[#]" '{if($0 ~/#/){s=$3;getline;print $2" "$3,s}else{print }}' OFS=" --> "

And the output i got is as this:

Code:
CH_PPV_AUDIT_DISTRIBUTOR
EL_CFG_FTP_DISTRIBUTOR  2.1.0.upc1  -->
CH_PPV_AUDIT_ENCODER
UPC_CFG_CH_PPV_AUDIT_ENCODER    1.0.2.  -->

As seen the new version is not printing. I tried to modify and see but no luck. Please have a look.

Last edited by radoulov; 10-05-2012 at 06:24 AM..
# 5  
Old 10-05-2012
Quote:
Originally Posted by rajangupta2387
Hi,

I used this awk command as below;
/usr/local/bin/gawk -F "[#]" '{if($0 ~/#/){s=$3;getline;print $2" "$3,s}else{print }}' OFS=" --> "

And the output i got is as this:

CH_PPV_AUDIT_DISTRIBUTOR
EL_CFG_FTP_DISTRIBUTOR 2.1.0.upc1 -->
CH_PPV_AUDIT_ENCODER
UPC_CFG_CH_PPV_AUDIT_ENCODER 1.0.2. -->


As seen the new version is not printing. I tried to modify and see but no luck. Please have a look.
there are two field separator and space is also one of the field separator... and you have used only # as field separator
try with awk -F "[# ]"

try this also..

Code:
awk -F "[# ]" 'NF == 1{print}
/NEW#/{s=$NF}
/OLD#/{print $2" "$3,s}' OFS=" --> " file

and as Elixir mentioned above please use code tags. see this

Last edited by pamu; 10-05-2012 at 06:34 AM..
# 6  
Old 10-05-2012
Have you tried the sed command? I hope it does not matter which tool you use to achieve your goal.
And again, please use code tags for code and data samples.

Last edited by elixir_sinari; 10-05-2012 at 07:11 AM..
# 7  
Old 10-05-2012
Hi,

Thanks for your answer. It worked as of now. But i have noticed one more improvement that need to be implemented. As stated below

Input:
Code:
Name
 NEW#TechnicalName1 Value1
 OLD#TechnicalName1  Value2
 NEW#TechinalName2 Value21
 OLD#TechnicalName2 Value 22

output
Code:
Name
 TechnicalName1 Value2 --> TechnicalName1 Value1
 TechinalName2 Value22 --> TechinalName2 Value21


how to achieve this senario?

Many Many thanks to All....!!!!

Last edited by Scott; 10-05-2012 at 09:01 AM.. Reason: Code tags
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