Problems with awk printf, formatted output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems with awk printf, formatted output
# 15  
Old 10-01-2012
@ Pamu & @ all

The above code works fine, but instead of hard coding can i use thea variable ?
# 16  
Old 10-01-2012
Quote:
Originally Posted by selvankj
but instead of hard coding can i use thea variable ?
try this - for using variables in awk...
Code:
awk -v FV="$first_var" -v SV="$second_var" '{ print FV,SV}' file

# 17  
Old 10-04-2012
@ Pamu

can we have a 'OR' conditon in awk ?? like the below
Code:
 
nawk -F, '$1=="3" && $4=="06" && $6=="C990" && ($9="89" || $9="90") {OFS=FS; if($2=="111") {$2="6H8"}.....

# 18  
Old 10-04-2012
Quote:
Originally Posted by selvankj
@ Pamu

can we have a 'OR' conditon in awk ?? like the below
Code:
 
nawk -F, '$1=="3" && $4=="06" && $6=="C990" && ($9=="89" || $9=="90") {OFS=FS; if($2=="111") {$2=="6H8"}.....

Yes. We can use OR in awk... like you have mentioned above..Smilie

like..
Code:
nawk -v VM="4" '(NR == VM || $0 > 4) && NR < 6 {print $0 }' file

# 19  
Old 10-04-2012
Thank you Pamu

But when i use more than one OR , i do not get expected results

Code:
 
nawk -F, '$1=="3" && $4=="06" && $6=="C990" && ( $9="6H8" || $9="6H9" || $9="6R8" )

# 20  
Old 10-04-2012
try using double ==

using single = sign it assigns the value to the variable..

try this...
Quote:
Originally Posted by selvankj
Code:
 
nawk -F, '$1=="3" && $4=="06" && $6=="C990" && ( $9=="6H8" || $9=="6H9" || $9=="6R8" )

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Formatted output in PERL

Hi Techies, I'm a newbie to PERL, Please help me with following problem. I have an input text file like below cat Input.txt 418673132,P 492538858,P 384535478,P 521522357,I 529435679,I 183617024,P 184414408,I 735510689,P 736238343,I 411642045,I 412690979,I 104232783,I (2 Replies)
Discussion started by: mahi_mayu069
2 Replies

2. Shell Programming and Scripting

Shell Script Problems, Lose formatting when copy pasting from formatted file.

Hello, I'm having trouble with formatting some text via the terminal. I can get it perfectly formatted, but when I try and copy paste the text from the output file it loses it's formatting. Very frustrating! Basically I have 7 files (data data2 data3 data4 data5 data6 data7) containing a... (13 Replies)
Discussion started by: facetoe
13 Replies

3. UNIX for Dummies Questions & Answers

Request for Formatted Output

Can you please tell me how to just get only the output of dealers I & V information along with their subtotals in the next line of the file and create a new file, The dealer position along with corresponding totals may change everyday to any position above or below in the file, please help Thanks (2 Replies)
Discussion started by: Ariean
2 Replies

4. Shell Programming and Scripting

output - tab formatted - awk

Dear All, Good Day. I would like to hear your suggestions for the following problem: I have a file with 5 columns with some numbers in 16 lines as shown below. Input file: Col 1 Col 2 Col 3 Col 4 Col 5 12 220 2 121 20 234 30 22 9... (3 Replies)
Discussion started by: Fredrick
3 Replies

5. Shell Programming and Scripting

How to format the output using float in awk{printf}

Hi I'm using awk to manipulate the data in the 6th field of the file xxx_yyy.hrv. The sample data that is available in this field is given below 220731.7100000000000000 When i tried using this command cat xxx_yyy.hrv | awk '{printf("%23.16f\n",$6*-1)}' I get the output as... (4 Replies)
Discussion started by: angelarosh
4 Replies

6. UNIX for Advanced & Expert Users

Help please...output problems with printf.

#include <stdio.h> #include <math.h> // this function calculates the volume of a Cylinder int main(void) { int r; // radius int h; // height double M_PI; // pi int pOne = pow (r, 2); // get user input of radius and height printf ("Enter your... (3 Replies)
Discussion started by: pwanda
3 Replies

7. Shell Programming and Scripting

Formatted Output

Hi I have the following lines in a file SWPRC000001NOT STATED 1344 SWPRC000001NOT STATED 1362 SWPRC000001NOT STATED 1418 SWPRC000001NOT STATED 1436 SWPRC000001NOT STATED ... (6 Replies)
Discussion started by: dhanamurthy
6 Replies

8. Shell Programming and Scripting

Formatted output - awk

Hi I have the following records in a file SABN YOURTUBE 000514 7256 SACN XYOUDSDF 000514 7356 SADN KEHLHRSER 000514 7656 SAEN YOURTUBE 000514 7156 SAFN YOURTUBE 000514 7056 I need to put this in the format like this printf '%s %-50s %6s %-6s\n' I am not going to read individual... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

9. Shell Programming and Scripting

Formatted output in KSH

Hi, Is there some way to get formatted output in ksh? Something like a properly alligned tabular format. I tried adding '\t' to echo statements, but it doesn't come properly alligned 'hello' A simple Hello 'helloworld' A helloworld statement I need the second coloumn to... (1 Reply)
Discussion started by: psynaps3
1 Replies

10. Shell Programming and Scripting

find: problems escaping printf-command string

Hi Folks! Can you help me with this find -printf command. I seem to be unable to execute the printf-command from my shell script. I'm confused: :confused: My shell script snippet looks like this: #!/bin/sh .. COMMAND="find ./* -printf '%p %m %s %u %g \n'" echo "Command: ${COMMAND}"... (1 Reply)
Discussion started by: grahamb
1 Replies
Login or Register to Ask a Question