substr() limitations in "AWK" program..!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting substr() limitations in "AWK" program..!!!
# 1  
Old 02-12-2008
Java substr() limitations in "AWK" program..!!!

Is there any limitation for the function substr()
Iam trying to assign some 11 digit number value to variable. And printing the variable. This is printing invalid values.

cur_val=substr($0,36,11);
printf "Current Value is: %d\n",cur_val


I tried till 9 digits length, it was working fine. If I select more than 10 digits problem occurs.

What could be the problem and what are the alternatives in awk script.

This would be helpful for all...

Thanks in advance / Lokiman
# 2  
Old 02-12-2008
substr will return the substring of the string provided. I am not clear wether you want to use this function or the index function
# 3  
Old 02-12-2008
This substr() function Iam using inside the 'awk' script to assign current record position values...
# 4  
Old 02-12-2008
It may be because of %d in printf, try %ld in printf

my be in ur unix version %d is having 9 digit limitation, but for me both %d and %ld is giving same result. Just try
# 5  
Old 02-12-2008
Quote:
Originally Posted by lokiman
Is there any limitation for the function substr()
Iam trying to assign some 11 digit number value to variable. And printing the variable. This is printing invalid values.

cur_val=substr($0,36,11);
printf "Current Value is: %d\n",cur_val


I tried till 9 digits length, it was working fine. If I select more than 10 digits problem occurs.

What could be the problem and what are the alternatives in awk script.

This would be helpful for all...

Thanks in advance / Lokiman
that statement says get the substring starting from position 36. make sure your $0 has more positions than that.
# 6  
Old 02-13-2008
Question $0 has 120 charecter length.

$0 has 120 charecter length.

I think this could be the limitation with the '%d'.
Are there any other reasons and alternatives?

Thanks
# 7  
Old 02-13-2008
till now, you have not shown your input file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Suggestion: adding two new groups "sed" and "awk"

Majority of the questions are pertaining file/string parsing w.r.t sed or awk It would be nice to have these two as their own sub category under shell-programming-scripting which can avoid lot of duplicate posts. (1 Reply)
Discussion started by: jville
1 Replies

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

perl file, one line code include "length, rindex, substr", slow

Hi Everyone, # cat a.txt a;b;c;64O a;b;c;d;ee;f # cat a.pl #!/usr/bin/perl use strict; use warnings; my $tmp3 = ",,a,,b,,c,,d,,e,,f,,"; open(my $FA, "a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\;/, $_); if ( ($tmp =~ m/^(64O)/i) || ($tmp... (3 Replies)
Discussion started by: jimmy_y
3 Replies

6. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

7. Shell Programming and Scripting

help for saving vertical datas to horizontal with "awk" or "cut"

hi, i have a file having datas like that ./a.txt 12344 12345 12346 12347 ..... ..... ... i want to save this datas to another file like that ./b.txt 12344 12345 12346 12347 ... ... ... i think awk can make this but how? :) waiting for ur help. (3 Replies)
Discussion started by: mercury
3 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Programming

how could i make a program mixed with many "|", "<" and ">"

I have written following code to do: ls -l | wc -w, it works: but when there are not only a single "|", if there are more such as: ls -l | sort -r | sort | sort -r, This program does not work, i want to know how could i deal with it when there are more "|", another situation is that, if it mixes... (2 Replies)
Discussion started by: strugglingman
2 Replies

10. UNIX for Dummies Questions & Answers

Any limitations to the "top" command?

Anyone know of any limitations? Also, does anyone know a great way to determine which processes are hogging CPU? TIA (6 Replies)
Discussion started by: lawadm1
6 Replies
Login or Register to Ask a Question