Search Results

Search: Posts Made By: beca123456
2,346
Posted By RavinderSingh13
Hello becal123456, IMHO problem in your code...
Hello becal123456,

IMHO problem in your code is that you haven't done any increment on very first occurrence of a[$2 FS $4 FS $5 FS $6 FS $7] and when it goes into condition check happens first...
2,367
Posted By RavinderSingh13
Thank you :) For your questions, why a[$1]...
Thank you :)

For your questions, why a[$1] didn't throw errors because if any variable is NOT initialized in awk and we are using it in any condition or etc then its value will be considered as...
2,367
Posted By RudiC
Try also awk -F\| ' {LN[NR] = $0 ...
Try also
awk -F\| '
{LN[NR] = $0
L = length($3)
if (L>MX[$2]) {MX[$2] = L
D3[$2] = $3
}
}
END {for...
2,367
Posted By RavinderSingh13
Hello beca123456, Could you please try...
Hello beca123456,

Could you please try following.


awk 'BEGIN{FS=OFS="|"} FNR==NR{b[$1]=length($3)>a[$1]?$3:b[$1];a[$1]=length($3)>a[$1]?length($3):a[$1];next} length($3)<a[$1]{$3=b[$1]} 1' ...
979
Posted By RudiC
You are overwriting the respective array elements...
You are overwriting the respective array elements with every occurrence of the respective customer. Try
awk -F"\t" '
NR == 1 {next
}

$2 ~ /grpA/ {a[$5] = a[$5]...
1,177
Posted By MadeInGermany
The regular expression search ~ is different from...
The regular expression search ~ is different from the string search via index.
You'll see differences e.g. with the following input files
A|123|qwer
A|456|tyui
A|45|wsxe
B|789|dfghA|123|qwer...
1,177
Posted By MadeInGermany
The following variant does a precise lookup (to...
The following variant does a precise lookup (to supress duplicates),
and does not need an array of delimiters:
awk '
BEGIN {
FS=OFS="|"
dl=";"
}
function strjoin(i, j){
if (i=="")...
1,177
Posted By RudiC
Do yourself a favour and start indenting /...
Do yourself a favour and start indenting / structuring your code for readability and understandability. Try

awk -F\| '
{if (!(a[$1] ~ $2)) a[$1] = a[$1] DL[$1] $2
if (!(b[$1] ~...
2,141
Posted By RudiC
Try "@val_num_desc"
Try "@val_num_desc"
4,737
Posted By RudiC
You are using gawk so it was quite safe to assume...
You are using gawk so it was quite safe to assume it provides delete. Other awk versions don't necessarily, use split ("", ARR) then to clear array ARR.
awk and other (not all!) languages use...
4,737
Posted By RudiC
For my convenience, I rearranged / -idented your...
For my convenience, I rearranged / -idented your code, and added the delete count statement:
awk -F"|" -vOFS="\t" '

{a = split ($2, b, ",")
for (i=1; i<=a; i++) if...
5,903
Posted By Don Cragun
Maybe something more like: gawk ' { VAR=0 ...
Maybe something more like:
gawk '
{ VAR=0
split($2,b,",")
for(i in b)
if(!(b[i] in s)) {
VAR++
s[b[i]]
}
print $1 "\t" VAR
for(i in s)
delete s[i]
}' input.tab
I don't...
3,115
Posted By Don Cragun
You might want to consider an alternative...
You might want to consider an alternative approach. No sprintf() calls, no for loops to gather your keys, and no long lists of explicitly copied arguments; just a single substr() call. And, it...
2,921
Posted By RudiC
!(DIG[1]) is a boolean expression that assumes...
!(DIG[1]) is a boolean expression that assumes the values 0 or 1 depending on that array element having a value or not. Actually above it is a - sometimes dicussed - shortcut for if (DIG[1] == 0)...
2,921
Posted By Aia
Sorry, I missed that in your request. awk ' ...
Sorry, I missed that in your request.

awk '
{
for(i=1;i<=length($0);i++){
ch = substr($0, i, 1)
if(ch ~ /[0-9]/){
d = ""
while(ch ~ /[0-9]/){
...
2,921
Posted By RudiC
Different approach:awk ' {printf "%s",...
Different approach:awk '
{printf "%s", $0
gsub (/[^A-Za-z0-9]/, "")
n = split ($0, DIG, "[A-Za-z]*")
m = split ($0, CHR, "[0-9]*")
S = CHR[1]
...
2,921
Posted By Don Cragun
Here is an alternative approach that will work...
Here is an alternative approach that will work with any standards-conforming version of awk. (Note that the standards say the behavior is unspecified if FS (or the ERE used in split()) is an empty...
6,791
Posted By Scrutinizer
A small variation, using reverse field...
A small variation, using reverse field separators, without sprintf and without FS="" :

awk '{n=split($2,O,/[^+-]+/); split($2,F,/[+-]/); $2=0; for(i=1; i<n; i++) $2+=(O[i+1] 1)*F[i]}1' FS=\|...
6,791
Posted By Don Cragun
This is a nice approach, and works fine with gawk...
This is a nice approach, and works fine with gawk and other awk implementations that use FS="" to split each input character into a field. A similar approach that doesn't depend on this behavior...
6,791
Posted By RudiC
Different approach, not sure if better/faster:awk...
Different approach, not sure if better/faster:awk '
{n = split ($2, T, "[+-]")
gsub (/[0-9]*/, _, $2)
split ($2, S, "")
for (t in T) $2 = $2 + sprintf ("%f",...
6,791
Posted By Don Cragun
I am having trouble following the logic of your...
I am having trouble following the logic of your script.

The diagnostic you are getting is because the sequence x(i) is a request to call the function named x with the parameter i, you haven't...
1,382
Posted By Don Cragun
You aren't far off. Using your indentation style...
You aren't far off. Using your indentation style and making a few minor changes:
gawk '
BEGIN{FS=OFS=" "}
NR==FNR{
brand[$1]=$2;
line[$1]=$0;
next
}
{
match($0,...
1,171
Posted By bakunin
What Don is telling you is (and this, btw., has...
What Don is telling you is (and this, btw., has nothing to do with the system being a cluster or not - it is simply the behavior of every shell i know of, including bash):

The PATH variable is a...
1,171
Posted By Don Cragun
Without telling us what the shared directory is...
Without telling us what the shared directory is (or the shared directories are), without telling us what program names exist in those shared directory or directories, and with the only sample program...
1,171
Posted By Don Cragun
You can't tell the cluster to do that, but you...
You can't tell the cluster to do that, but you can modify your .bashrc file on that cluster by resetting PATH after you source the shared initialization file:
source /home/shared/bashrc...
Showing results 1 to 25 of 70

 
All times are GMT -4. The time now is 09:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy