I have to add pipes for particualr number of records in a file. For eg the file has 10 records and i need to add the "|" for records numbers 7 to 10 at particular positons as shown.
I need to add pipes in each of these records at positions 9, 11,,21 as like below.
function setFieldsByWidth( i,n,FWS,start,copyd0)
{
copyd0 = $0
n = split(FIELDWIDTHS,FWS)
if (n == 1) {
print "Warning: FIELDWIDTHS contains only one fie"
print "Attempting to continue." > "/dev/stderr"
}
start = 1
for (i=1; i <= n; i++) {
$i = substr(copyd0,start,FWS)
start = start + FWS
}
}
BEGIN {
FIELDWIDTHS="8 2 10 9999"
OFS="|"
}
FNR >=7 && FNR<=10 && !/^[ ]*$/ {
saveDollarZero = $0 # if you want it later
setFieldsByWidth()
# now we can manipulate $0, NF and $1 .. $NF as we wish
print $0
next
}
1
function setFieldsByWidth( i,n,FWS,start,copyd0)
{
copyd0 = $0
n = split(FIELDWIDTHS,FWS)
if (n == 1) {
print "Warning: FIELDWIDTHS contains only one fie"
print "Attempting to continue." > "/dev/stderr"
}
start = 1
for (i=1; i <= n; i++) {
$i = substr(copyd0,start,FWS)
start = start + FWS
}
}
BEGIN {
FIELDWIDTHS="8 9999"
OFS="|"
}
!/^[ ]*$/ {
saveDollarZero = $0 # if you want it later
setFieldsByWidth()
# now we can manipulate $0, NF and $1 .. $NF as we wish
print $0
next
}
1