kif1205 / Linux

0 stars 0 forks source link

SED example #11

Open kif1205 opened 5 years ago

kif1205 commented 5 years ago

sed -n 's/(La)/\1Oo/p' dataf3 把找到的 La 存起來,用 \1 取回來使用 sed -i 取代修改原始檔

將多個空白取代成逗號 $ sed -r "s/[ ]+/,/g" sed_space.data

轉成dos文字檔 sed -i 's/$/\r/' xxx.txt

sed '1,4d' xxx.txt 刪除 1 至 4 列

sed '/YYY/d' xxx.txt 刪除含有 YYY 字串的列

sed '/[0-9]{3}/d' xxx.txt 把含有 3個數字的列刪除

sed '/^$/d' ttt 把 ttt 檔案中的空白列刪除。

sed '/YYY/!d' xxx.txt 把不含有 YYY 的列刪除

sed -n '/AAA/s/234/567/p' dataf3 找到含有 AAA 的那一列之後,將 234 換成 567

sed -n '/AAA/,/DDD/s/B/567/p' dataf3 含有 AAA 一直到含有 DDD 的那幾列,皆將其中的 B 換成 567

sed -n '2,4s/B/567/p' dataf3 由第 2 列到第 4 列,皆將其中的 B 換成 567

kif1205 commented 4 years ago

sed -i 's/"LogEFIStatusCodes": "[A-z|0-9|:punct:|.| ]*"/"LogEFIStatusCodes": "Error code"/' /etc/bios_current.json


MaxCountOfEventSubscriptions in eventingMode.conf is below :

MaxCountOfEventSubscriptions=100

Command : "sed -n '/^MaxCountOfEventSubscriptions=/ {s///p;q;}' /usr/local/etc/nginx/eventingMode.conf

Output : 100


Replace EventingMechanism=* as EventingMechanism=0

Command : sed -i 's/EventingMechanism=[A-z|0-9|:punct:|.| |,|/]*/EventingMechanism=0" + "/' " + EventingMode_Conf_File_Path


kif1205 commented 4 years ago

2019.08.20

Command :

sed -n '/^[ ]*"DependencyFor": "Era/ {=s///p;q;}' /usr/local/nginx/www/BiosAttributeRegistry/VertivBiosAttributeRegistry.1.0.0.json

Result :

928
seSEL",

=> 928 is the match number ,' seSEL", ' is the match word


Result :

928
kif1205 commented 4 years ago

2019.08.20

Original

                    "MapToProperty": "GrayOut",
                    "MapToValue": true
                },
                "DependencyFor":"fdsafsadfas",
                "Type": "Map"
            },
            {
                "Dependency": {

920~930 "DependencyFor":[A-z|0-9|:punct:|.| |,|/|\"]*, =>"DependencyFor":"123",

sed -i '920,930s/"DependencyFor":[A-z|0-9|:punct:|.| |,|/|\"]*,/"DependencyFor":"123",/g' /usr/local/nginx/www/BiosAttributeRegistry/VertivBiosAttributeRegistry.1.0.0.json

Result :

                    "MapToProperty": "GrayOut",
                    "MapToValue": true
                },
                "DependencyFor":"123",
                "Type": "Map"
            },
            {
                "Dependency": {
kif1205 commented 4 years ago

2019.08.28