Printing symbols with some condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing symbols with some condition
# 1  
Old 04-27-2013
Printing symbols with some condition

hi ..all I have an urgency of doing some task so I am posting here...please help

i tried this ...its not working properly

Code:
awk '{if($1>p)print $0;else $1=$2="*";print $0}'

pls find attachment

my input file is like this
Code:
0    25.2    11-Jan-1971    6.45    1040    SU
1    25.2    11-Jan-1971    6.45    1040    SU
2    25.2    11-Jan-1971    6.45    1040    SU
3    25.2    11-Jan-1971    6.45    1040    SU
4    25.2    11-Jan-1971    6.45    1040    SU
5    25.2    11-Jan-1971    6.45    1040    SU
6    25.2    11-Jan-1971    6.45    1040    SU
7    25.1    11-Jan-1971    6.45    1040    SU
8    25.1    11-Jan-1971    6.45    1040    SU
9    25.1    11-Jan-1971    6.45    1040    SU
10    25.1    11-Jan-1971    6.45    1040    SU
5    24.93    12-Jan-1971    7.45    1041    SU
6    24.9    12-Jan-1971    7.45    1041    SU
7    24.9    12-Jan-1971    7.45    1041    SU
8    24.9    12-Jan-1971    7.45    1041    SU
9    24.9    12-Jan-1971    7.45    1041    SU
10    24.89    12-Jan-1971    7.45    1041    SU
11    24.89    12-Jan-1971    7.45    1041    SU
12    24.89    12-Jan-1971    7.45    1041    SU
13    24.89    12-Jan-1971    7.45    1041    SU
14    24.89    12-Jan-1971    7.45    1041    SU
15    24.89    12-Jan-1971    7.45    1041    SU
1    25.2    13-Jan-1971    9.63    1049    US
2    25.2    13-Jan-1971    9.63    1049    US
3    25.2    13-Jan-1971    9.63    1049    US
4    25.2    13-Jan-1971    9.63    1049    US
5    25.2    13-Jan-1971    9.63    1049    US
6    25.2    13-Jan-1971    9.63    1049    US
7    25.1    13-Jan-1971    9.63    1049    US
8    25.1    13-Jan-1971    9.63    1049    US
9    25.1    13-Jan-1971    9.63    1049    US
10    25.1    13-Jan-1971    9.63    1049    US
5    25.2    14-Jan-1971    10.45    1050    AUS
6    25.2    14-Jan-1971    10.45    1050    AUS
7    25.1    14-Jan-1971    10.45    1050    AUS
8    25.1    14-Jan-1971    10.45    1050    AUS
9    25.1    14-Jan-1971    10.45    1050    AUS
10    25.1    14-Jan-1971    10.45    1050    AUS

expecting output like this
Code:
*    *    11-Jan-1971    6.45    1040    SU
0    25.2    11-Jan-1971    6.45    1040    SU
1    25.2    11-Jan-1971    6.45    1040    SU
2    25.2    11-Jan-1971    6.45    1040    SU
3    25.2    11-Jan-1971    6.45    1040    SU
4    25.2    11-Jan-1971    6.45    1040    SU
5    25.2    11-Jan-1971    6.45    1040    SU
6    25.2    11-Jan-1971    6.45    1040    SU
7    25.1    11-Jan-1971    6.45    1040    SU
8    25.1    11-Jan-1971    6.45    1040    SU
9    25.1    11-Jan-1971    6.45    1040    SU
10    25.1    11-Jan-1971    6.45    1040    SU
*    *    12-Jan-1971    7.45    1041    SU
5    24.93    12-Jan-1971    7.45    1041    SU
6    24.9    12-Jan-1971    7.45    1041    SU
7    24.9    12-Jan-1971    7.45    1041    SU
8    24.9    12-Jan-1971    7.45    1041    SU
9    24.9    12-Jan-1971    7.45    1041    SU
10    24.89    12-Jan-1971    7.45    1041    SU
11    24.89    12-Jan-1971    7.45    1041    SU
12    24.89    12-Jan-1971    7.45    1041    SU
13    24.89    12-Jan-1971    7.45    1041    SU
14    24.89    12-Jan-1971    7.45    1041    SU
15    24.89    12-Jan-1971    7.45    1041    SU
*    *    13-Jan-1971    9.63    1049    US
1    25.2    13-Jan-1971    9.63    1049    US
2    25.2    13-Jan-1971    9.63    1049    US
3    25.2    13-Jan-1971    9.63    1049    US
4    25.2    13-Jan-1971    9.63    1049    US
5    25.2    13-Jan-1971    9.63    1049    US
6    25.2    13-Jan-1971    9.63    1049    US
7    25.1    13-Jan-1971    9.63    1049    US
8    25.1    13-Jan-1971    9.63    1049    US
9    25.1    13-Jan-1971    9.63    1049    US
10    25.1    13-Jan-1971    9.63    1049    US
*    *    14-Jan-1971    10.45    1050    AUS
5    25.2    14-Jan-1971    10.45    1050    AUS
6    25.2    14-Jan-1971    10.45    1050    AUS
7    25.1    14-Jan-1971    10.45    1050    AUS
8    25.1    14-Jan-1971    10.45    1050    AUS
9    25.1    14-Jan-1971    10.45    1050    AUS
10    25.1    14-Jan-1971    10.45    1050    AUS

# 2  
Old 04-27-2013
Code:
awk '
        function p_asterisk()
        {
                n = split ( $0, A )
                A[1] = A[2] = "*"
                for ( i = 1; i <= n; i++ )
                        printf A[i] OFS
                printf "\n"
        }
        p != $3 {
                p_asterisk()
                p = $3
        }
        p == $3 {
                print $0
                p = $3
        }
' OFS='\t' file

# 3  
Old 04-27-2013
Try also
Code:
$ awk '$3 != tmp {X=$0; $1=$2="*"; print; $0=X; tmp=$3} 1' OFS="\t" file

Your script does not work because you compare $1 to p, but p is never set, so equals to zero, so the comparison is always true, printing every line twice.
# 4  
Old 04-28-2013
RudiC Sir...this I tried resulting same

Code:
awk '
NR==1 || $1<p{
{
for(i=1;i<=NF;i++)
A[i]=$i
}
{
A[1]="*"
A[2]="*"
}
{for(i=1;i<=NF;i++)
printf "%s%s",A[i],OFS;printf "\n"}
}{print;p=$1}' OFS=\\t file


Last edited by Akshay Hegde; 04-28-2013 at 03:20 AM.. Reason: typo..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

2. UNIX for Dummies Questions & Answers

Help with understanding the symbols '~#' and '~$'

I noticed that sometimes there is "~#" or "~$" in the terminal. What is that? I can't make any research in google because I don't know what are they called. I even tried reading pdf's or books but unfortunately, I wasn't lucky to find out. Maybe I was not persistent enough but I am really... (3 Replies)
Discussion started by: chams
3 Replies

3. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

4. Shell Programming and Scripting

Script printing else condition

Please help what is wrong in below script. It is printing else also, else echo "DATABASE NOT RUNNING :${i} ================================================= #!/usr/bin/ksh set -A DBS $(cat /etc/oratab | grep ":Y" | awk -F : '{print $1}') set -A RDBS $(ps -ef | grep -i pmon | grep... (3 Replies)
Discussion started by: allwin
3 Replies

5. UNIX for Dummies Questions & Answers

Sco Unix printing : jobs hangs in queue - printing via lp versus hpnpf

Hi, We have a Unix 3.2v5.0.5. I installed a printer via scoadmin, HP network printer manager with network peripheral name (hostname and ipadres are in /etc/hosts). This is the configuration file : Code: root@sco1 # cat configurationBanner: on:AlwaysContent types: simpleDevice:... (0 Replies)
Discussion started by: haezeban
0 Replies

6. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

7. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

8. Programming

cc -- Unsatisfied symbols -- on HP-UX 10.2

Greetings, I am slowly learning a few things but am far from being an expert. I am at the point now that I would like to be able write some ANSI C code on HP-UX 10.2. Just a hobbie... I am just using cc, which came with the HP-UX 10.2 ... I don't have the manuals for the development... (7 Replies)
Discussion started by: Dirk_
7 Replies

9. Shell Programming and Scripting

Printing records which meet condition using awk

Below is the code nawk -F"|" 'tolower($1) ~ "abc" |"" {if (tolower($2) ~"abc"|"") print$0}' file I want the records from file whose 1st and 2nd field should be either "abc" or "null" I tried but its giving error. Appreciate help (2 Replies)
Discussion started by: pinnacle
2 Replies

10. Shell Programming and Scripting

redirecting symbols

Can anyone please tell me what the following do 1. < 2. << Thanks Calypso (1 Reply)
Discussion started by: Calypso
1 Replies
Login or Register to Ask a Question