Home > OS >  How to substitution character in a particular place
How to substitution character in a particular place

Time:10-04

I want to put the serial number of the following information (DEV_SERIAL_NUMBER) in the seventh and eighth (02) into 4, with the shell how to implement, please teach a great god,
DEV_NAME=""
DEV_OEMNAME=""
A000488 DEV_SERIAL_NUMBER="300024022", "
MAC_ADDRESS="94-05: B6:5 f: 29: CF"
MANUFACTURING_DATE="2018-09-22"
VENDOR_NAME="Cetron"
A000488 MANU_SERIAL_NUNBER="300024022", "
CLEI_CODE=""
BUILD_INFO=""
MAC_ADDRESS_COUNT="1 dec"
DEVICE_BOM="BOM - 2143
"A000488 BOARD_SERIAL_NUMBER="300024022", "
CUSTOMER_CODE=""

CodePudding user response:

The
reference
#!/bin/bash

# # # out 300024022 a000488 field
NUM=$(awk - "=" F '/^ DEV_SERIAL_NUMBER/{print $2}' triple-a. TXT | awk - F '"' '{print $2}')

# # # # replace 02 to 04
NUM_NEW=` echo $NUM | sed 's @ \ [[0-9 a zA - Z] \ \ {6} \) 02 @ \ 104 @' `
Replace 02 # # # # of the two characters for 04
# NUM_NEW1=` echo $NUM | sed 's @ \ [[0-9 a zA - Z] \ \ {6} \) \ [[0-9 a zA - Z] \ \ {2} \) @ \ 104 @' `

# # # to replace 300024022 a000488 into a new field in file
Sed - ir '/^ DEV_SERIAL_NUMBER/s @ \="(. *) \ \ (. *) \ \ (\) @ " 1' "$NUM_NEW" '\ 3 @' triple-a. TXT


See if your 02 fixed string, can use NUM_NEW, fluid can use NUM_NEW1, also can use NUM_NEW1 directly, remember to sed substitution variables
  • Related