本文介绍了我需要从位置X删除字符串中的文本文件到位置y每行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的平面文件100K记录每一个横跨3000列。我需要删除的数据段菲起始位置300归档前定位500。这是数据的敏感部位需要被消灭之前,我可以存档。
我要寻找一个AWK或SED或任何类似的命令能为我做的伎俩。

I have a huge flat file 100K records each spanning 3000 columns. I need to removed a segment of the data fay starting position 300 to position 500 before archiving. This is sensitive part of data that needs to be wiped before I can archive.I am looking for a awk or sed or any similar command that can do the trick for me.

示例文件

003133780 MORNING GLORY DR                                        SOUTHAMPTON         PA18966780 MORNING GLORY DR
0054381303 MADISON ST                                             RADFORD             VA241411303 MADISON ST
00586728 CONESTOGA COURT                                          CHADDS FORD         PA1931728 CONESTOGA COURT
1852921800 SAMER RD                                               MILAN               MI481601800 SAMER RD
192717175 EVERGREEN CIRCLE                                        HENDERSONVILLE      TN37075175 EVERGREEN CIRCLE
213673217 EAST BRANCH                                             LONGVIEW            TX75604217 EAST BRANCH
2490423205 NOTTAGE LANE                                           FALLS CHURCH        VA220423205 NOTTAGE LANE
249357344 BALOGH PLACE                                            LONGWOOD            FL32750344 BALOGH PLACE
2502811224 WILFORD HOLLOW ROAD                                    VINTON              VA241791224 WILFORD HOLLOW ROAD
277634210 AMANDA CT                                               WHITEHOUSE          TX7579119726 COPPER OAKS DRIVE
282482507 B ST.                                                   CHESAPEAKE          VA23324507 B ST.

期望的输出

003133780 MORNING GLORY DR                                        SOUTHAMPTON         PA780 MORNING GLORY DR
0054381303 MADISON ST                                             RADFORD             VA1303 MADISON ST
00586728 CONESTOGA COURT                                          CHADDS FORD         PA28 CONESTOGA COURT
1852921800 SAMER RD                                               MILAN               MI1800 SAMER RD
192717175 EVERGREEN CIRCLE                                        HENDERSONVILLE      TN175 EVERGREEN CIRCLE
213673217 EAST BRANCH                                             LONGVIEW            TX217 EAST BRANCH
2490423205 NOTTAGE LANE                                           FALLS CHURCH        VA3205 NOTTAGE LANE
249357344 BALOGH PLACE                                            LONGWOOD            FL344 BALOGH PLACE
2502811224 WILFORD HOLLOW ROAD                                    VINTON              VA1224 WILFORD HOLLOW ROAD
277634210 AMANDA CT                                               WHITEHOUSE          TX19726 COPPER OAKS DRIVE
282482507 B ST.                                                   CHESAPEAKE          VA507 B ST.

下面我删除了89位和95之间的字符。
一个小小的改变,我还需要编写改变的内容相同的文件。

Here I removed the char between position 89 and 95.One small change, I also need to write the changed content to the same file.

下面是脚本我有这么远。
我通过循环的所有文件,将它们分为最大行20000的文件,然后在归档前去除位置的X和Y的特点。

Below is the script I have so far.I am looping through all files, dividing them into files of max rows 20000 and then removing the characters from position X and Y before archiving.

LS currentfilename -1 *。[标题] [XX] [标题]

回声$ currentfilename
tempfilename = $ {currentfilename %%。*}
AWK -v A =$ tempfilename'{文件名= A的部分的INT((NR-1)/ 20000)名.txt;打印>>文件名}$ currentfilename
AWK'{打印SUBSTR(0,1,522 $)SUBSTR($ 0953)>>文件名}$ currentfilename
MV $ currentfilename $ APP_ROOT /存档

for currentfilename in ls -1 *.[tT][xX][tT]doecho $currentfilenametempfilename=${currentfilename%%.*}awk -v A="$tempfilename" '{filename = A "Part" int((NR-1)/20000) ".txt"; print >> filename}' $currentfilenameawk '{print substr($0,1,522) substr($0,953) >> filename}' $currentfilenamemv $currentfilename $APP_ROOT/Archivedone

推荐答案

假设位置的意思是字符

awk '{print substr($0,1,299) substr($0,501)}' file

如果它不然后编辑你的问题,以添加一些RE preSENTATIVE样本输入和预期的输出(例如5行,每行6列,而不是几千上万列线的)。

If it doesn't then edit your question to add some REPRESENTATIVE sample input and expected output (e.g. 5 lines of 6 columns each, not thousands of lines of thousands of columns).

这篇关于我需要从位置X删除字符串中的文本文件到位置y每行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-31 07:49