简体   繁体   English

Bash,列中数据的大量数据更改,但仅特定行

[英]Bash, mass data change on data from a column but only specific lines

I have a data file that I need to do a mass date change on specific lines or column.我有一个数据文件,需要对特定行或列进行批量日期更改。 It is only on specific lines that end in 0003-0.它仅在以 0003-0 结尾的特定行上。 There are many others similar and I do not need them changed.还有许多其他类似的,我不需要更改它们。 I am attaching an example.我附上一个例子。 Under column Due I need to change the date to a newer date but only on lines that have the ending with -0 I think I can do it for 0003-0 as they are the same.在 Due 列下,我需要将日期更改为较新的日期,但仅限于以 -0 结尾的行,我认为我可以为 0003-0 执行此操作,因为它们是相同的。 It needs to be a bash script.它需要是一个 bash 脚本。 I have tried awk and grep egrep with little success.我试过 awk 和 grep egrep 但收效甚微。

                         User id: CR                        24-FEB-22
                    Active Orders Report                     Page   5


141543B              NS N     14     14 NO 220224 12468064-0003-1               
144461-003B          NS N     16     16 NO 220225 12473061-0003-1               
143092B              NS N      9      9 NO 220225 12472857-0003-1               
153674-002G          NS N     10     10 NO 220225 12477592-0003-1               
150543B              NS N    243    243 NO 220228 12477208-0003-1               
145874D              NS N     96     96 NO 220228 12477238-0003-1               
140725D              NS N    140    140 NO 220228 12476411-0003-1               
------------------------------------------------------------------------------
 Material name: 915028-120-60         Thk:    0.375
 
Part name            ST F OrgQty Qty    PR Due    Order number
-------------------- -- - ------ ------ -- ------ ------------------------------
138540-005H          NS N      3      3 NO 220224 12469166-0003-1               
134305-005H          NS N     17     17 NO 220224 12468143-0003-1               
134305-004H          NS N     17     17 NO 220224 12468699-0003-1               
138540-003H          NS N      1      1 NO 220224 12469164-0003-1               
134305-004H          NS N     17     17 NO 220225 12472767-0003-1               
134305-025H          NS N     18     18 NO 220225 12473151-0003-1               
134305-004H          NS N     17     17 NO 220228 12476502-0003-1               
134305-005H          NS N     17     17 NO 220228 12476974-0003-1               
134305-025H          NS N     10     10 NO 220228 12475684-0003-1               
134305-004H          NS N     17     17 NO 220228 12476418-0003-1               
------------------------------------------------------------------------------
 Material name: 915028-120-48         Thk:    0.375
 
Part name            ST F OrgQty Qty    PR Due    Order number
-------------------- -- - ------ ------ -- ------ ------------------------------
166764-003B          NS N      8      8 NO 220225 12472406-0003-1               
166764-003B          NS N      8      8 NO 220228 12476160-0003-1               
------------------------------------------------------------------------------
 Material name: 915028-119-48         Thk:    0.375
 
Part name            ST F OrgQty Qty    PR Due    Order number
-------------------- -- - ------ ------ -- ------ ------------------------------
134914-001D          NS N     46     46 NO 220101 12478187-0003-0               
134307-005K          NS N     19     19 NO 220101 12470436-0003-0               
134838E              NS N    150    150 NO 220101 12474868-0003-0               
134307-005K          NS N     19     19 NO 220101 12474436-0003-0               
146376C              NS N     24     24 NO 220203 12468515-0003-1

           
$ awk -v d='270503' '$NF ~ /-0$/{$0 = substr($0,1,43) d substr($0,50)} 1' file
                         User id: CR                        24-FEB-22
                    Active Orders Report                     Page   5


141543B              NS N     14     14 NO 220224 12468064-0003-1
144461-003B          NS N     16     16 NO 220225 12473061-0003-1
143092B              NS N      9      9 NO 220225 12472857-0003-1
153674-002G          NS N     10     10 NO 220225 12477592-0003-1
150543B              NS N    243    243 NO 220228 12477208-0003-1
145874D              NS N     96     96 NO 220228 12477238-0003-1
140725D              NS N    140    140 NO 220228 12476411-0003-1
------------------------------------------------------------------------------
 Material name: 915028-120-60         Thk:    0.375

Part name            ST F OrgQty Qty    PR Due    Order number
-------------------- -- - ------ ------ -- ------ ------------------------------
138540-005H          NS N      3      3 NO 220224 12469166-0003-1
134305-005H          NS N     17     17 NO 220224 12468143-0003-1
134305-004H          NS N     17     17 NO 220224 12468699-0003-1
138540-003H          NS N      1      1 NO 220224 12469164-0003-1
134305-004H          NS N     17     17 NO 220225 12472767-0003-1
134305-025H          NS N     18     18 NO 220225 12473151-0003-1
134305-004H          NS N     17     17 NO 220228 12476502-0003-1
134305-005H          NS N     17     17 NO 220228 12476974-0003-1
134305-025H          NS N     10     10 NO 220228 12475684-0003-1
134305-004H          NS N     17     17 NO 220228 12476418-0003-1
------------------------------------------------------------------------------
 Material name: 915028-120-48         Thk:    0.375

Part name            ST F OrgQty Qty    PR Due    Order number
-------------------- -- - ------ ------ -- ------ ------------------------------
166764-003B          NS N      8      8 NO 220225 12472406-0003-1
166764-003B          NS N      8      8 NO 220228 12476160-0003-1
------------------------------------------------------------------------------
 Material name: 915028-119-48         Thk:    0.375

Part name            ST F OrgQty Qty    PR Due    Order number
-------------------- -- - ------ ------ -- ------ ------------------------------
134914-001D          NS N     46     46 NO 270503 12478187-0003-0
134307-005K          NS N     19     19 NO 270503 12470436-0003-0
134838E              NS N    150    150 NO 270503 12474868-0003-0
134307-005K          NS N     19     19 NO 270503 12474436-0003-0
146376C              NS N     24     24 NO 220203 12468515-0003-1

Seems I am asking about the wrong input as this is the output that needs to have the date changed and is run by another program.似乎我在询问错误的输入,因为这是 output 需要更改日期并由另一个程序运行。 What I need to do is find in a.csv file the date that has a corresponding -0 on the end and change dates for those to say todays date.我需要做的是在 a.csv 文件中找到末尾有相应 -0 的日期,并将日期更改为今天的日期。 I was going to grep -o to find this but I may just use awk to find the 6th column and change the date for those columns to todays date.我打算去grep -o找到这个,但我可能只使用 awk 找到第 6 列并将这些列的日期更改为今天的日期。

no, quantity, ordered, date, order no
133346B       36     36 NO 220225 12473014-0003-1               
089122-018M   2      2 NO 220225 12472891-0003-1               
166563A       76     76 NO 220225 12473558-0003-1               
089122-018M   2      2 NO 220228 12476638-0003-1               
091075G       60     60  NO 220228 12477089-0003-1               
133160-MFGA   8      8 NO 220101 12474637-0003-0               
147461-MFGA   39     39 NO 220101 12474816-0003-0               
105176C       66     66 NO 220101 12474805-0003-0               
144076-MFGB   112    112 NO 220101 12474813-0003-0               
137602A       120    120 NO 220101 12474867-0003-0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM