Visit Our UNIX and Linux User Community

Search Results

Search: Posts Made By: ken6503
1,793
Posted By RavinderSingh13
Hello ken6503, Could you please try...
Hello ken6503,

Could you please try following and let me know if this helps.

awk -F", " '($2 ~ /\.[0-9]{3}+/){print $1,$2}' Input_file
Output will be as follows.

xyz, 123456.789
Also I...
1,793
Posted By Don Cragun
That is a good start. The ERE you are using is...
That is a good start. The ERE you are using is matching a decimal point followed by two decimal digits (which as you have found only matches lines with exactly two decimal places) at the end of the...
1,793
Posted By itkamaraj
try this... awk -F,...
try this...

awk -F, '{split($2,Arr,".")}length(Arr[2])>2' test
1,793
Posted By Aia
awk -F"," '$2 ~ /\.[0-9][0-9][0-9]/'...
awk -F"," '$2 ~ /\.[0-9][0-9][0-9]/' test
1,765
Posted By RavinderSingh13
Hello ken6503, Could you please try...
Hello ken6503,

Could you please try following and let me know if this helps you.

awk -F"," 'function abs(value){sum+=value;return sum} {abs($8)}{;print sum OFS $8} END{printf("%.2f\n",sum)}' ...
1,765
Posted By balajesuri
awk -F "," '$8 < 0{$8=$8*-1} {sum+=$8} END...
awk -F "," '$8 < 0{$8=$8*-1} {sum+=$8} END {printf "%.2f\n", sum}' file
1,765
Posted By RudiC
How about {sum+=$8<0?-$8:$8}? You need to...
How about {sum+=$8<0?-$8:$8}?

You need to declare/define the abs function if you want to use it.
2,229
Posted By greet_sed
Interesting solutions so far :b: Here is my...
Interesting solutions so far :b:

Here is my try, in perl:
perl -pe 'if($. == 1 || eof) {s/,/ /g}' file
2,229
Posted By Scrutinizer
Indeed, sed is the most suitable for this...
Indeed, sed is the most suitable for this application, when removing trailing comma's only on the first and last line.

Yet, here is another approach using awk, removing trailing comma's only on...
2,229
Posted By RavinderSingh13
Hello All/Ken6503, One more approach here...
Hello All/Ken6503,

One more approach here which is based on that if first or last lines will always have consecutive 4 commas as like shown Input_file, then following may help in same too.

awk...
2,229
Posted By blastit.fr
What a funny contest. On the same way : $...
What a funny contest.
On the same way :
$ awk 'FNR == 1 && NR != 1{last=NR-1}NR == FNR{next}FNR == 1 || FNR ==last{gsub(",",X)} 1 ' file.txt file.txt
2,229
Posted By RudiC
RavinderSingh13: Interesting approach ... awk...
RavinderSingh13: Interesting approach ...
awk 'gsub(/,/, _, $1) && gsub (/,/, _, $NF)' RS="" FS="\n" OFS="\n" file
2,229
Posted By blastit.fr
The shortest way : $ awk -v last=$(wc -l...
The shortest way :
$ awk -v last=$(wc -l <file.txt) 'NR==1 || NR==last{gsub(",","")}1' file.txt
2,229
Posted By RavinderSingh13
Hello Ken6503, Could you please try...
Hello Ken6503,

Could you please try following too and let me know if this helps you.

awk '{for(i=1;i<=NF;i++){if(i==1 || i==NF){gsub(/,/,X,$i);print $i} else {print $i};}}' RS="" FS="\n" ...
2,229
Posted By RudiC
Try also awk 'FNR == 1 || FNR == c {c = NR-1;...
Try also
awk 'FNR == 1 || FNR == c {c = NR-1; gsub(",",X)} FNR < NR' file file
2,229
Posted By Yoda
Another approach by reading file twice:- awk...
Another approach by reading file twice:-
awk 'NR==FNR{++c;next}FNR==1||FNR==c{gsub(",",X)}1' file file
2,229
Posted By RudiC
awk doesn't know about the last line when it...
awk doesn't know about the last line when it works on the last line, only afterwards. So it's not THAT easy in awk:
awk 'LAST {print LAST}; NR==1 {gsub (/,/,_)}; {LAST = $0} END {gsub (/,/, _,...
2,229
Posted By RudiC
Your sample file has an empty first line, so no...
Your sample file has an empty first line, so no commas, and the following wouldn't work:
sed '1s/,//g;$s/,//g' file
ABC HEADER TOTAL RECORDS ARE 2.00
C,300,ABC,BC,
C,400,ABC,TO,
ABC TRAILER....
1,167
Posted By MadeInGermany
-n tests the following token for non-empty. But...
-n tests the following token for non-empty.
But the [ ] is a test command, and does not see the empty value of $p at all, but it sees a "" as an empty token.
The result for -n without a following...
1,167
Posted By Scrutinizer
You are welcome. If you try: ( set -x; [ -n $p...
You are welcome. If you try:
( set -x; [ -n $p ] && [ -n "$p" ])
+ '[' -n ']'
+ '[' -n '' ']'
You'll notice that the first one evaluates to -n and the second one to -n ''

In the first case the...
1,167
Posted By MadeInGermany
Thanks, I have updated my code in post#2.
Thanks, I have updated my code in post#2.
1,167
Posted By Scrutinizer
Another variation while read p do [ -n...
Another variation
while read p
do
[ -n "$p" ] && para="$para,'$p'"
done < file
para=${para#,}


---
Small correction to MadeInGermany's suggestion:
para="${para:+"${para}",}'$p'"
1,275
Posted By RavinderSingh13
Hello Ken6503, You haven't shown us the...
Hello Ken6503,

You haven't shown us the expected output, so I am not sure either we need to put both conditions of having number of fields lesser than 5 + $NF(last field's) value should be grater...
1,275
Posted By neutronscott
That may be the most correct way but a quick way...
That may be the most correct way but a quick way to get the same output is to just append the new value and the field separator inside of $1.


mute@tiny:~$ awk 'NF<5{$1=$1 FS "XXX"}1' FS=, OFS=,...
1,199
Posted By Don Cragun
Assuming that the first field will always be...
Assuming that the first field will always be exactly one of those three characters, you could also try something like:
awk -F'|' '{print > ($1=="D"?d:$1=="H"?h:t)}' d="$det_name" h="$hea_name"...
Showing results 1 to 25 of 170

 

Featured Tech Videos

All times are GMT -4. The time now is 05:45 PM.
Unix & Linux Forums Content Copyright 1993-2021. All Rights Reserved.
Privacy Policy