Home > OS >  Bash, mass data change on data from a column but only specific lines
Bash, mass data change on data from a column but only specific lines

Time:04-08

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. 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. It needs to be a bash script. I have tried awk and grep egrep with little success.

                         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

           

CodePudding user response:

The simplest awk solution would be:

awk '$8 ~ /-0003-0$/ {$7 = "XXXXXX"} 1'

But it will mess up your pretty column alignments.

For working around that you could do:

awk '$8 ~ /-0003-0$/ {sub(" "$7" "," XXXXXX ")} 1'

CodePudding user response:

$ 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
  • Related