![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help needed with Sort and uniq data | asirohi | Shell Programming and Scripting | 4 | 08-17-2009 09:25 PM |
| How to replicate data using Uniq or awk | ahjiefreak | Shell Programming and Scripting | 5 | 08-19-2008 02:25 AM |
| Compare 2 files and give uniq output | rauphelhunter | Shell Programming and Scripting | 1 | 05-12-2008 05:47 PM |
| compare two col from 2 files, and output uniq from file 1 | pp56825 | Shell Programming and Scripting | 2 | 01-10-2008 11:10 AM |
| Modify files | amgo | UNIX for Advanced & Expert Users | 7 | 12-12-2005 09:19 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Modify log files to get uniq data
Hello, I have a log file that has following output as below. Code:
LAP.sun5 CC LAP.sun5 CQ perl.sun5 CC perl.sun5 CQ TSLogger.sun5 CC TSLogger.sun5 CQ TSLogger.sun5 KR WAS.sun5 CC WAS.sun5 MT WAS.sun5 CQ I want to output to be in the way below, i tried using awk but could not do it. Code:
LAP.sun5 CC CQ perl.sun5 CC CQ TSLogger.sun5 CC CQ KR WAS.sun5 CC MT CQ Please help . how do i do that Thanks Adsi Last edited by asirohi; 08-24-2009 at 05:12 PM.. |
|
|||||
|
Quote:
Code:
$
$ cat data.txt
LAP.sun5 CC
LAP.sun5 CQ
perl.sun5 CC
perl.sun5 CQ
TSLogger.sun5 CC
TSLogger.sun5 CQ
TSLogger.sun5 KR
WAS.sun5 CC
WAS.sun5 MT
WAS.sun5 CQ
$
$ awk '{if (prev == ""){printf("%s",$0)}
else if($1 == prev){printf(" %s",$2)}
else {printf("\n%s",$0)} prev=$1
} END {printf "\n"}' data.txt
LAP.sun5 CC CQ
perl.sun5 CC CQ
TSLogger.sun5 CC CQ KR
WAS.sun5 CC MT CQ
$
$
tyler_durden |
|
||||
|
Hello Tyler, Thanks for the wonderful explaination, that was superb. I have a question if(prev == "") and i dont want to display any thing what do i do. I asked this question because in the log files there are $1 fields that occur only once and i dont want to display them. For example HTML Code:
[COLOR=Red]Linix CQ[/COLOR] LAP.sun5 CC LAP.sun5 CQ perl.sun5 CC perl.sun5 CQ TSLogger.sun5 CC TSLogger.sun5 CQ TSLogger.sun5 KR WAS.sun5 CC WAS.sun5 MT WAS.sun5 CQ [COLOR=Red]Sun.log CC[/COLOR] So the output should be as below and should leave $1 field if it has no previous value. LAP.sun5 CC CQ perl.sun5 CC CQ TSLogger.sun5 CC CQ KR WAS.sun5 CC MT CQ Code:
$ awk '{if (prev == ""){printf("%s",$0)}
else if($1 == prev){printf(" %s",$2)}
else {printf("\n%s",$0)} prev=$1
} END {printf "\n"}' data.txt
Last edited by asirohi; 08-25-2009 at 10:48 AM.. Reason: code tags, PLEASE! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|