awk changes to cut number of digits


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk changes to cut number of digits
# 1  
Old 07-03-2013
awk changes to cut number of digits

Code:
HCPM1ONDB00014800011800000589009211201




Code:
L201307022013070228AUD  00000000031.       000965105800000000000000000000000                                   MOBITV KEYA                                       ZB00        BI-194428444435          00000000                                                                                                                                    00000000      00000000000           00000000



I want to subtract 00096510580 from 00000589009211. script is doing every thing, but i want only first 11 digits of $3(00096510580) in variable R instead of
whole $3(000965105800000000000000000000000)


Code:
nawk ' NR == 1 {
                HF = substr($0,1,15);
                HC = substr($0,16,6);
                HR = substr($0,22,14);
                HE = substr($0,36,3);
                HS = substr($0,39);
} /MOBITV/ {
                R  = $3;
                sub(/0+$/,x,R);
                HC -= 2;
                HR -= R;
                getline; next;
} !/MOBITV/ {
                print $0 > "newfile";
} END {
                printf "%s%06d%014d%-385d", HF, HC, HR, HE, HS > "header";
} ' $1

HDR=$( cat header )

nawk -v H="$HDR" 'NR==1{ sub($0,H) }1' newfile > temp


Code:
 R  = $3;
       sub(/0+$/,x,R);

I want R = first 11 digits of $3 and also tell me after that is
Code:
sub(/0+$/,x,R);

required?
# 2  
Old 07-03-2013
If you want the first 11 digits, then use awk substr function:
Code:
R = substr ( $3, 1, 11 )

You don't need sub(/0+$/,x,R) after that.
# 3  
Old 07-03-2013
Quote:
Originally Posted by Yoda
If you want the first 11 digits, then use awk substr function:
Code:
R = substr ( $3, 1, 11 )

You don't need sub(/0+$/,x,R) after that.
This is not working

I am getting different value. it is not subtracting 00096510580 from 00000589009211..
it is doing some action and printing different output in header with - sign
# 4  
Old 07-03-2013
I put some print statements:
Code:
} /MOBITV/ {
                R = substr ( $3, 1, 11 );
                print R, HR
                HC -= 2;
                HR -= R;
                print R, HR
                getline; next;
}

and this is what I get:
Code:
00096510580 00000589009211
00096510580 492498631

It seems to subtract 00096510580 from 00000589009211 [ 00000589009211 - 00096510580 = 492498631 ]

I would suggest you to put few more debugs and check what is going on.
# 5  
Old 07-03-2013
Quote:
Originally Posted by Yoda
I put some print statements:
Code:
} /MOBITV/ {
                R = substr ( $3, 1, 11 );
                print R, HR
                HC -= 2;
                HR -= R;
                print R, HR
                getline; next;
}

and this is what I get:
Code:
00096510580 00000589009211
00096510580 492498631

It seems to subtract 00096510580 from 00000589009211 [ 00000589009211 - 00096510580 = 492498631 ]

I would suggest you to put few more debugs and check what is going on.
Thanks worked fine now with some minor changes
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies

2. Shell Programming and Scripting

Bash detecting number of digits in line

Hi I have a problem, I am attempting to write a bash script that goes through a file and can determine how many characters are at a set point in a line starting with QTY+113:100:PCE, If it detects 3 digits (number in bold) then pad it out with 12 zero's If there are only two digits then pad it... (8 Replies)
Discussion started by: firefox2k2
8 Replies

3. Shell Programming and Scripting

Find number of digits in a word

HI, Can you tell me how to find the number of digits in a word. $cat data.txt +123456ad 87645768 Output should be 6 8 (5 Replies)
Discussion started by: ashwin3086
5 Replies

4. Shell Programming and Scripting

extracting Number variable and the following digits.

HI all, I have output of something like this: crab: ExitCodes Summary >>>>>>>>> 12 Jobs with Wrapper Exit Code : 50117 List of jobs: 1-12 See https:///twiki/something/ for Exit Code meaning crab: ExitCodes Summary >>>>>>>>> 5 Jobs with Wrapper Exit Code : 8001 List of... (20 Replies)
Discussion started by: emily
20 Replies

5. Shell Programming and Scripting

summing the digits of a binary nuMBER

please help me write a perl program to find the difference of 1 and zeros of a 6 digit binary number. eg If input is 111100 expected output +2 if input is 000011 expected output -2 input is 000111 expected output 0 (2 Replies)
Discussion started by: dll_fpga
2 Replies

6. Shell Programming and Scripting

number of digits after decimal

Hi All, I have a file of decimal numbers, cat file1.txt 1.1382666907 1.2603107334 1.6118799297 24.4995857056 494.7632588468 560.7633734425 ..... I want to see the output as only 7 digits after decimal (5 Replies)
Discussion started by: senayasma
5 Replies

7. Shell Programming and Scripting

Use match() in nawk to find digits in number

Hi, I just need to check whether number of digits in a phone number is 10 or not. If I am not wrong regex will be: {9} I have to use this inside nawk as this is a small portion of a big program. nawk ' BEGIN { RS="";FS=";"; regex="{9}"; } { for (i=1;i<=NF;i++) { if... (6 Replies)
Discussion started by: shekhar2010us
6 Replies

8. Shell Programming and Scripting

Count number of digits in a word

Hi all Can anybody suggest me, how to get the count of digits in a word I tried WORD=abcd1234 echo $WORD | grep -oE ] | wc -l 4 It works in bash command line, but not in scripts :mad: (12 Replies)
Discussion started by: ./hari.sh
12 Replies

9. Shell Programming and Scripting

How to cut last 10 digits off

Hi I'm new to this. I need to cut off the last 10 digits from a line. I've used awk {'print $4'} filename.txt | cut -c 32-42 but this does not guarantee only the last 10 characters. Please help. Thanks. Sara (4 Replies)
Discussion started by: psarava
4 Replies

10. UNIX for Advanced & Expert Users

restrain the number of digits of a PID

How is it possible under UNIX to restrain the number of digits of the PID number? For instance, we have a product that generates a PID of 7 digits, and we would like to have only 6 digits maximum instead for the PID. Thank you for your help. (1 Reply)
Discussion started by: mlefebvr
1 Replies
Login or Register to Ask a Question