cancel
Showing results for 
Search instead for 
Did you mean: 

awk question:

SOLVED
Go to solution
Sharvil Desai
Frequent Advisor

awk question:

Hi everyone!
Using awk, how can I say that anytime while processing a file if characters 10&11 of any line are non-numeric then convert them to 99. Please help soon, this is VIP.
"help!"
3 REPLIES
John Meissner
Esteemed Contributor
Solution

Re: awk question:

i wrote this really quick - it should point you in the right direction:

cat file |
while read file
do
var10=$cat file | sed -n '1p' | awk '{print $10}' | grep -v [0-9])
var11=$cat file | sed -n '1p' | awk '{print $11}' | grep -v [0-9])
echo "cat file | sed 's/$var10/99/g' file >> file.out
echo "cat file | sed 's/$var11/99/g' file >> file.out
unsed var10 var11
done
chmod +x file.out
./file.out
All paths lead to destiny
John Meissner
Esteemed Contributor

Re: awk question:

all you would need is an "if then" statement in there and you'll be set.
All paths lead to destiny
Rodrigo Ramos
Occasional Visitor

Re: awk question:

Hy!

I don't know if you need anymore, but...

the simple form is to create a script with the following content:


awk '{
num=substr($0,10,2);
if ((num<00)||(num>99))
print substr($0,1,9) "99" substr($0,12);
else print $0;

}' $1


is faster than the last solution... in my case, it's the most important because I work with thousand files of more than 1 Gb each...

so, after that, change the file permission with "chmod +x FILE" ...


ready!!

put:


./FILE TEXT_TO_CONVERT



[s]
Rodrigo Ramos