Add "1234" to specific field in second column

i have this file

073274753,0544901701,20101201,000316
038873722,69647455,20101130,235257
26213399,0545335767,20101201,000930
063330167,0566000101,20101201,000226
026773376,11966,20101130,234429,1194
075431120,0565900600,20101201,000428
75431120,0565900600,20101201,000538
038239110,0569224091,20101130,235616
035933611,0568580075,20101130,235939
025668601,0565651151,20101201,000046

i need if i have in first column any number doesn't start with zero i will add zero to it like this

75431120,0565900600,20101201,000538
075431120,0565900600,20101201,000538

also if i have in second column any number doesn't start with zero add "1234" to it

026773376,11966,20101130,234429,1194
026773376,123411966,20101130,234429,1194

and print all lines in the file "modificated and non modificated" all

awk 'BEGIN{FS=OFS=","}
    $1 !~ /^0/{$1="0"$1}
    $2 !~ /^0/{$2="1234"$2}1' file
1 Like
awk 'BEGIN{FS=OFS=","}     $1 !~ /^0/{$1="0"$1}     $2 !~ /^0/{$2="1234"$2}1' file

could you explain why you add "1" ?

That will print all the lines. Implicitly call the below,

1{print;}

1 can be replaced by any positive integer.

Cheers,
Ranga:)

thats equivalent to print $0, means prints all the contents.

# awk 'BEGIN{FS=OFS=","}
    $1 !~ /^0/{$1="0"$1}
    $2 !~ /^0/{$2="1234"$2} {print $0}' file

073274753,0544901701,20101201,000316
038873722,123469647455,20101130,235257
026213399,0545335767,20101201,000930
063330167,0566000101,20101201,000226
026773376,123411966,20101130,234429,1194
075431120,0565900600,20101201,000428
075431120,0565900600,20101201,000538
038239110,0569224091,20101130,235616
035933611,0568580075,20101130,235939
025668601,0565651151,20101201,000046
1 Like

1 is same as we use print .

The same above you can also write with print.

awk 'BEGIN{FS=OFS=","}
    $1 !~ /^0/{$1="0"$1}
    $2 !~ /^0/{$2="1234"$2}{print}' file

1 may be replaced with any non-zero number, positive or negative.