Sponsored Content
Full Discussion: awk conditional statement
Top Forums Shell Programming and Scripting awk conditional statement Post 302083844 by mukundranjan on Tuesday 8th of August 2006 06:09:35 AM
Old 08-08-2006
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);} '

Smilie Smilie Smilie Smilie Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

quoting in conditional statement

can somebody help, what quote i should use in below statement or what wrong of it ? the 1st (*) is a char, the 2nd and 3rd (*) is a wildcard if ] && ] && ] ................^ .............^ then echo "ok" fi thanks in advance. (2 Replies)
Discussion started by: 3Gmobile
2 Replies

2. Shell Programming and Scripting

conditional statement

Hi Does Unix have a conditional statement like Java as follows: Condition ? Statement1 : Statement2 Thanks (8 Replies)
Discussion started by: lalelle
8 Replies

3. Shell Programming and Scripting

conditional statement

Hi all, The following code is to find if a list of numbers from one file are within the range in another file. awk -F, '\ BEGIN { while ((getline < "file2") > 0) file2=$3 } {for (col1 in file2) if ($0>=30 && $1<=45) print $0} ' FILE1 But where I have the number 30 and 45, I... (3 Replies)
Discussion started by: dr_sabz
3 Replies

4. Shell Programming and Scripting

if conditional statement

Hi, I have a script like this: sample.sh mapping=$1 if then echo "program passed" fi I'm running the above script as ./sample.sh pass The script is not getting executed and says "integer expression expected" Could anyone kindly help me? (2 Replies)
Discussion started by: badrimohanty
2 Replies

5. UNIX for Dummies Questions & Answers

Conditional statement in bash

I want to combine 2 conditional statements by using -o in bash, but it won't work. if ; then echo "The number needs to be between 0 and $nr" fi Each time i execute the file it says: ./selectCitaat: line 10: syntax error near unexpected token `$1' (3 Replies)
Discussion started by: doc.arne
3 Replies

6. Shell Programming and Scripting

awk conditional statement issue

I have a file like this i want to filter out records whose date is greater than '2010-11-20'. I have written this code like this... cat /etl/ruby/purge/output/PurgeCLC15.DSINT.sort_inptnt_otptnt_prequalify.ruby.dat | awk '{ substr($0,12,10) == '2010-11-20' print substr($0,12,10) }' ... (3 Replies)
Discussion started by: issaq84mohd
3 Replies

7. Shell Programming and Scripting

Conditional Shell Statement

I want to add a conditional statement to a user's .profile file. I have a certain number of users that log in and use the rksh (Restricted Korn Shell). When they log in, it starts a certain program and when they exit this program, the system logs them out. When they are in this program, they can... (2 Replies)
Discussion started by: rjulich
2 Replies

8. UNIX for Advanced & Expert Users

conditional statement

I need to implement something like this. 1) search for a file(say *.doc) from a path (say /home/user/temp) 2) if file found & if file size > 0 : yes --> file valid else : print file not valid. I am trying to implement something like this, but seems i am terribly wrong somewhere.. ... (1 Reply)
Discussion started by: animesharma
1 Replies

9. Shell Programming and Scripting

conditional statement in awk

Hi all, I have a file containing the values that would be use as the basis for printing the lines of another set of files using awk. What I want to do is something like the one below: stdev.txt 0.21 0.42 0.32 0.25 0.15 file1.txt file2.txt file3.txt ..filen.txt 0.45 0.23 ... (4 Replies)
Discussion started by: ida1215
4 Replies

10. Programming

Getting error at conditional statement.

Hi experts, I am doing an exercise which has the following requirements. Charlie will bite your finger exactly 50% of the time. First, write a function isBitten() that returns TRUE with 50% probability, and FALSE otherwise To generate a webpage that displays "Charlie bit your finger!" or... (1 Reply)
Discussion started by: Navneet_das_123
1 Replies
DEBUG_BACKTRACE(3)							 1							DEBUG_BACKTRACE(3)

debug_backtrace - Generates a backtrace

SYNOPSIS
array debug_backtrace ([int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT], [int $limit]) DESCRIPTION
debug_backtrace(3) generates a PHP backtrace. PARAMETERS
o $options - As of 5.3.6, this parameter is a bitmask for the following options: debug_backtrace(3) options +-------------------------------+---------------------------------------------------+ |DEBUG_BACKTRACE_PROVIDE_OBJECT | | | | | | | Whether or not to populate the "object" index. | | | | | DEBUG_BACKTRACE_IGNORE_ARGS | | | | | | | Whether or not to omit the "args" index, and | | | thus all the function/method arguments, to save | | | memory. | | | | +-------------------------------+---------------------------------------------------+ Before 5.3.6, the only values recognized are TRUE or FALSE, which are the same as setting or not setting the DEBUG_BACKTRACE_PRO- VIDE_OBJECT option respectively. o $limit - As of 5.4.0, this parameter can be used to limit the number of stack frames returned. By default ($limit= 0) it returns all stack frames. RETURN VALUES
Returns an array of associative arrays. The possible returned elements are as follows: Possible returned elements from debug_backtrace(3) +---------+--------------------------------------+---+ | Name | | | | | | | | | Type | | | | | | | | Description | | | | | | +---------+--------------------------------------+---+ |function | | | | | | | | | | | | | string | | | | | | | | The current function name. See also | | | | __FUNCTION__. | | | | | | | line | | | | | | | | | | | | | integer | | | | | | | | The current line number. See also | | | | __LINE__. | | | | | | | file | | | | | | | | | | | | | string | | | | | | | | The current file name. See also | | | | __FILE__. | | | | | | | class | | | | | | | | | | | | | string | | | | | | | | The current class name. See also | | | | __CLASS__ | | | | | | | object | | | | | | | | | | | | | object | | | | | | | | The current object. | | | | | | | type | | | | | | | | | | | | | string | | | | | | | | The current call type. If a method | | | | call, "->" is returned. If a static | | | | method call, "::" is returned. If a | | | | function call, nothing is returned. | | | | | | | args | | | | | | | | | | | | | array | | | | | | | | If inside a function, this lists | | | | the functions arguments. If inside | | | | an included file, this lists the | | | | included file name(s). | | | | | | +---------+--------------------------------------+---+ CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.4.0 | | | | | | | Added the optional parameter $limit. | | | | | 5.3.6 | | | | | | | The parameter $provide_object changed to | | | $options and additional option DEBUG_BACK- | | | TRACE_IGNORE_ARGS is added. | | | | | 5.2.5 | | | | | | | Added the optional parameter $provide_object. | | | | | 5.1.1 | | | | | | | Added the current object as a possible return | | | element. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 debug_backtrace(3) example <?php // filename: /tmp/a.php function a_test($str) { echo " Hi: $str"; var_dump(debug_backtrace()); } a_test('friend'); ?> <?php // filename: /tmp/b.php include_once '/tmp/a.php'; ?> Results similar to the following when executing /tmp/b.php: Hi: friend array(2) { [0]=> array(4) { ["file"] => string(10) "/tmp/a.php" ["line"] => int(10) ["function"] => string(6) "a_test" ["args"]=> array(1) { [0] => &string(6) "friend" } } [1]=> array(4) { ["file"] => string(10) "/tmp/b.php" ["line"] => int(2) ["args"] => array(1) { [0] => string(10) "/tmp/a.php" } ["function"] => string(12) "include_once" } } SEE ALSO
trigger_error(3), debug_print_backtrace(3). PHP Documentation Group DEBUG_BACKTRACE(3)
All times are GMT -4. The time now is 10:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy