You can start with this awk
and build on it as you need.
awk '
BEGIN {
FS = " *[|] *" # Set the Field Separator to this pattern
OFS = "," # Set the Output Field Separator to ,
}
NF { # Skip blank lines
$1 = $1 # Reconstruct your input line
gsub(/^,|,$/,"") # Remove leading and trailing ,
lines[++i] = $0 # Add line to array
}
END {
for(x=4;x<=i-2;x++) # Skip first three and last two lines
print lines[x] # Print line
}' file
ABDULHADI, ASHRAF M,2,1990,3
ACHANTA, BALA,2,1995,3
ACHANTA, BALA,2,1996,3
If your data does not have blank lines then you can remove NF
and use NR
as key instead of ++i
FS
pattern above is zero or more spaces followed by pipe (placed in character class to consider it literal, since it is a meta character) followed by zero or more spaces.