I'm processing a file in awk.
I want to pass along the rows in the file that have blanks in column positions 25 through 34 and I want to do work on the rows that have blanks in column positions 10 through 19. Specifically I want to replace the blanks in columns positions 10 through 19 with 0s. That way the output file will have the original rows with blanks in 25-34 untouched. and the rows with blanks in 10-19 with have been replaced with '0's. So the output file will be the same as the input file only with zeros in the relevant rows in positions 10-19. The file looks like this:
###########################################
######### ########################
###########################################
###########################################
###########################################
###########################################
###########################################
###########################################
######### ##### #########
###########################################
###########################################
###########################################
I know I have to use an if block but I've never used one before in awk. The syntax below is what I think I need but please help me with the details. Specifically what I'm using to specify 'blanks' in the if statements.
I apologize ahead of time for the bad syntax. This is my first time using an If block in awk. I know the syntax doesn't work, which is one of the reasons I'm posting this.
cat scr2 | awk 'BEGIN {
pos1=substr($0,25,10);
pos2=substr($0,10,10);
if (pos1 = ^[[:blank:]]$)
printf $0
else if (pos2 == ^[[:blank:]]$)
{val=substr($0,25,10)}
gsub(/ /,0,val){$0=substr($0,1,24) val substr($0,35)} 1}'`
The sample output would be :
###########################################
#########0000000000########################
###########################################
###########################################
###########################################
###########################################
###########################################
###########################################
######### ##### #########
###########################################
###########################################
###########################################
So the row with blanks only at positions 10-19 gets changed and the row with blanks at both 10-19 and 25-34 get left alone.