Print Positional variables


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Print Positional variables
# 1  
Old 06-04-2012
Print Positional variables

Hi,

I have to use the vaious kind of filters based on various fields in the input file like - count occurence of cases where "TRK-GRP" = 169 or like "ADDR-DIG" = 80080.

I don;t know the positional variable for all below fields. Please help.

Input File :
Code:
+++ BEST 12-05-27 15:06:49 MDI 3478 #459313 >
   REPT MDI ATO     SIGTYPE ISUP7NATL  PROTOCOL NONE      
   TRK-GRP 169          MEMBER 4     TGSIZE 30    DEN=5-0-9-36
   TKGMOOS 0         CALL-DIR OGT       SERVICE POTS 
   ADDR-DIG 80080                                        
   LAST-DIG 5        TRIAL 1        DATE 12-05-27  CALLTYPE NORMAL
   TIME 15:06:43     CATEGORY C          
   
   
   END OF REPORT #459313 ++-

Moderator's Comments:
Mod Comment Please view this link: How to use [code]...[/code] tags

Last edited by Scrutinizer; 06-05-2012 at 03:54 AM.. Reason: code tags
# 2  
Old 06-04-2012
This should print the the position of everything as well as its contents.

Code:
awk -v RS="" '{ for (N=1; N<=NF; N++) print N, $N ; printf("\n"); }' filename

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-05-2012
Quote:
Originally Posted by Corona688
This should print the the position of everything as well as its contents.

Code:
awk -v RS="" '{ for (N=1; N<=NF; N++) print N, $N ; printf("\n"); }' filename

Thanks..it made my life easy Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Positional Parameters Arguments/Variables when using dot (.)

Hi, Is there a special positional variables for when using the dot (.)? Scripts are as below: $: head -100 x.ksh /tmp/y.ksh ==> x.ksh <== #!/bin/ksh # . /tmp/y.ksh 1234 abcd echo "yvar1 = $yvar1" echo "yvar2 = $yvar2" ==> /tmp/y.ksh <== #!/bin/ksh (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Compare two variables and print the difference

Hi PRIM_SEQ=`some sql code` and output of PRIM_SEQ is like below 120 130 STB_SEQ=`some sql code` and output of STB_SEQ is like below 115 110 i need to compare this two variables output ( decimal numbers) 1) What I want to do is to compare every number in the PRIM_SEQ with... (8 Replies)
Discussion started by: amar1208
8 Replies

3. Shell Programming and Scripting

Print whole line if variables matches

Der colleagues, 4 days I am trying to solve my issue and no success.. Maybe you can give me a clue how to achieve what I need.. So I have two files. file1 example: 1_column1.1 1_column2.1 aaa 1_column4.1 1_column1.2 1_column2.2 ttt 1_column4.2 1_column1.3 1_column2.3 ... (10 Replies)
Discussion started by: nypreH
10 Replies

4. Shell Programming and Scripting

PRINT TWO VARIABLES IN ONE LINE

my command nawk -F' ' '{for(i=1;i<=NF;i++){if ($i ~ /XX/) print i}}' TOM.bk The output is in two lines as below 12 30 i want the output in one line with comma delimited as below 12,30 the 23 and 79 are column numbers in one line of the file. so i want all the two columns... (1 Reply)
Discussion started by: dealerso
1 Replies

5. Shell Programming and Scripting

To print variables using awk

Can anyone help me with how to print the variable using a awk statement. for i in ` cat serverlist.txt ` ; do my command | awk '{print $1 $2 $i}' done It should print like below but it is not XXXXX YYYYY Servername XXXXX YYYYY Servername XXXXX YYYYY Servername XXXXX YYYYY... (6 Replies)
Discussion started by: rrb2009
6 Replies

6. Shell Programming and Scripting

Problem with positional variables in BASH

Hello, my problem is simple & I searched a lot but I couldn't find anything about it: Basically I'd like to pass $i to a variable, $i being the positional variable; but it is unknown in the beginning so I can't do it like eg. myvar=$3, it HAS to be the "i".. First, I tried myvar=$($i) ... (8 Replies)
Discussion started by: timmyyyyy
8 Replies

7. Shell Programming and Scripting

For Loop And Print 2 Variables

I have the following loop: for I in `ldm ls |grep -v ^NAME| awk '{print $1}'` do ldm ls -o network $I | echo $I | tr -s ' ' | cut -f6 -d " " | more +9 I would like the following displayed to a file: The value of $I, followed by a newline, then the information from the rest of the... (3 Replies)
Discussion started by: hxman
3 Replies

8. Shell Programming and Scripting

AWK: replace single positional character given variables

I already have accomplished this task using sed and arrays, but since I get the variable using awk, I figured I'd ask this question and maybe I can get a cleaner solution using strictly awk.. I just can't quite grasp it in awk. Story: I'm automating the (re)configuration of network interfaces,... (3 Replies)
Discussion started by: System Shock
3 Replies

9. Shell Programming and Scripting

How can I print variables im using in makefiles?

for example in my make file im building path from env variables and string but need to see what is did what is the best way to print the result? say I have in my Makefile : exec_prefix = $(RUN_ENV_LOCAL)/apache and I will like to print the exec_prefix value , how can it be done ? (1 Reply)
Discussion started by: umen
1 Replies

10. Shell Programming and Scripting

cannot print 3 variables on same line

Hi, I have a file containing emails about some issues. Using a bourne shell script, I need to extract the issue number from the URL's contained in the file (all URL's look like this : http://www.openoffice.org/issues/show_bug.cgi?id=1881) and then print out the issue number, status and... (2 Replies)
Discussion started by: Chris Jones
2 Replies
Login or Register to Ask a Question