shizik
1
Hi all
In input file I have records like this:
0,1,0,87,0,0,"6,87","170,03",0,"43,5",0,0,0,0,"6,87","126,53"
and in output file I need that these records transforms in :
0 1 0 87 0 0 6,87 170,03 0 43,5 0 0 0 0 6,87 126,53
Could you help me in this case? Please
Please read the The UNIX and Linux Forums - Forum Rules and do not cross/multiple post
awk '{gsub(","," ");$0=gensub("\"([0-9]+) ([0-9]+)\"","\\1,\\2","g");print}' infile
There is not even an error message? What system are you running? You need to be more specific if you want us to help you.
shizik
8
ok
my system
SunOS test01 5.10 Generic_138888-01 sun4u sparc SUNW,Sun-Fire-280R
an error:
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
Check if you have gawk installed.
shizik
10
2bartus11
no
only awk and nawk
The easiest way to solve that problem is to install gawk I think it is included in Solaris 10 Companion CD.
You could also use Perl:
perl -pe 's/,/ /g;s/\"([0-9]+) ([0-9]+)\"/\1,\2/g' infile
1 Like
shizik,
what's wrong with the sed approaches in the other thread?
my $str='0,1,0,87,0,0,"6,87","170,03",0,"43,5",0,0,0,0,"6,87","126,53"';
$str=~s/(,)(?=
[^"]*$
|
(?:(?:[^",]*,)*(?:"[^"]*",)*(?:[^",]*,)*)*(?:[^",]+|"[^"]*")$
)/ /xg;
$str=~s/"//g;
print $str;