从不均匀间隔的文本文件中提取表数据

从不均匀间隔的文本文件中提取表数据
         CLASS RECORD OF THE STUDENT FROM THE PREVIOUS BATCH WHO TOPPED
Name (Roll no) #    Location   Section     Rank (MARKS)     Gender   
Anna (+)            USA        A1          First (100)      Female
(04)                California V
ADDITIONAL RECORDS OF THE STUDENTS FROM THE PREVIOUS BATCH NEXT IN LIST
Name (Roll no) #    Location   Section     Rank (MARKS)     Gender
Bob (-)             USA        A2          First (99)       Male
(07)                Florida    VI
Eva (+)             USA        A4          Second (96)      Female
(12)                Ohio       V           English (99)
                                           Maths(100)
Other records are not available currently.Some records may be present which can be given on request.

使用以下命令从 PDF 中获取文本文件pdf转文本。使用下面AWK命令我正在获取上述数据。
表数据的空间分隔不均匀。删除以下行全线是在大写

pdftotext -layout INPUTFILE.pdf INPUTFILE.txt
awk '/RESULTS/{flag=1;next}/OTHER DATA/{flag=0}flag' INPUTFILE.txt | column -ts $'\t' -n


如何获取制表符分隔格式的表数据(以下格式)?
以通用方式编码,因此它也适用于其他类型的表。

Name (Roll no) #    Location    Section     Rank (MARKS)    Gender  
Anna (+)            USA         A1          First (100)     Female
(04)                California  V
Bob (-)             USA         A2          First (99)      Male
(07)                Florida     VI
Eva (+)             USA         A4          Second (96)     Female
(12)                Ohio        V           English (99)
                                            Maths (100)

答案1

让我知道这是否是您要找的

$ awk '{if ($1 in a) next; a[$1]=$0; print}' <filePath> | grep -v  -e STUDENT  -e Other | column -ts $'\t' 
Name (Roll no) #    Location   Section     Rank (MARKS)     Gender   
Anna (+)            USA        A1          First (100)      Female
(04)                California V
Bob (-)             USA        A2          First (99)       Male
(07)                Florida    VI
Eva (+)             USA        A4          Second (96)      Female
(12)                Ohio       V           English (99)
                                           Maths(100)

相关内容