![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| If statement - How to write a null statement | april | Shell Programming and Scripting | 3 | 04-16-2008 01:14 PM |
| AWK - conditional cause | Rafael.Buria | Shell Programming and Scripting | 2 | 01-28-2008 01:24 PM |
| conditional statement | lalelle | Shell Programming and Scripting | 8 | 08-21-2007 08:57 AM |
| quoting in conditional statement | 3Gmobile | Shell Programming and Scripting | 2 | 08-14-2006 03:14 AM |
| more elegant way for conditional statement needed | candyflip2000 | Shell Programming and Scripting | 3 | 05-18-2006 07:52 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
awk conditional statement
how can i use awk or sed to do a conditional statement, so that
HH:MM if MM not great than 30 , then MM=00 else MM=30 ie: 10:34 will display 10:30 10:29 will display 10:00 a=$(echo 10:34 | awk ......) Thanks in advance |
|
||||
|
Hi friend,
I have written below 2 line of code, 1. create a file with of diffrent value that we will use for testing. 2. Cat that file and check for the second parameter if it is greater than 30 then it will print 30. else it will print 00. You can put any value in place of other parameter. Code:
1. for((i=0;i<60;i++)); do echo "HH:$i:XX:YY:ZZ" >> tmp.txt; done
2. cat tmp.txt | awk -F":" '{ if($2<30) printf("%s:00:%s:%s:%s\n",$1,$3,$4,$5);} { if($2>30) printf("%s:30:%s:%s:%s\n",$1,$3,$4,$5);} '
![]() |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|