sed

Removing duplicate strings with SED

假装没事ソ 提交于 2021-02-10 07:18:21
问题 I use buildroot package to port some software packages to some Linux embedded system. Some software packages also produce plain text script and/or library control files with references to staging directories. It is necessary to remove the references to staging directories at the stage of packaging the software for distribution. I have no problem to use SED to remove such references. However, this processing leaves some undesired patterns of duplicate strings and I excerpted as shown below. I

Data Conversion Using Sed or Awk - Name to Title

落花浮王杯 提交于 2021-02-10 07:17:07
问题 I have data in the below format: APP_OWNER : hari APP_AREA : Work:Business Area:AUS APP_ID : 124080 APP_OWNER : ari APP_AREA : Work:AUS APP_ID : 124345 I want the data to be converted to below format. APP_OWNER,APP_AREA,APP_ID hari,Work:Business Area:AUS,124080 ari,Work:AUS,124345 I can convert one line but how to do it with 3 lines at the same time? My Attempt with one line sed '0,/: /s//\n/' test.txt Original Question : Convert Rows to Columns Shell Script Regards 回答1: Here is an awk

Delete pattern from a variable with sed

折月煮酒 提交于 2021-02-09 12:28:13
问题 I am working with a script that has a variable called PRODUCT_VERSION . The version comes with a dot (for example 6.0 ). I need to remove the dot and save the result in another variable. So far I come with this, but it does not work correctly PRD_VER=$(sed "s/$PRODUCT_VERSION/\.//g") 回答1: $ PRODUCT_VERSION=6.0 $ PRD_VER=${PRODUCT_VERSION/.} $ echo $PRD_VER 60 Bash String Manipulation Examples 回答2: This might work for you (GNU sed & bash): NEW=$(sed 's/\.//g' <<<"$OLD") or NEW=$(echo "$OLD" |

Delete pattern from a variable with sed

♀尐吖头ヾ 提交于 2021-02-09 12:27:53
问题 I am working with a script that has a variable called PRODUCT_VERSION . The version comes with a dot (for example 6.0 ). I need to remove the dot and save the result in another variable. So far I come with this, but it does not work correctly PRD_VER=$(sed "s/$PRODUCT_VERSION/\.//g") 回答1: $ PRODUCT_VERSION=6.0 $ PRD_VER=${PRODUCT_VERSION/.} $ echo $PRD_VER 60 Bash String Manipulation Examples 回答2: This might work for you (GNU sed & bash): NEW=$(sed 's/\.//g' <<<"$OLD") or NEW=$(echo "$OLD" |

Delete pattern from a variable with sed

£可爱£侵袭症+ 提交于 2021-02-09 12:25:20
问题 I am working with a script that has a variable called PRODUCT_VERSION . The version comes with a dot (for example 6.0 ). I need to remove the dot and save the result in another variable. So far I come with this, but it does not work correctly PRD_VER=$(sed "s/$PRODUCT_VERSION/\.//g") 回答1: $ PRODUCT_VERSION=6.0 $ PRD_VER=${PRODUCT_VERSION/.} $ echo $PRD_VER 60 Bash String Manipulation Examples 回答2: This might work for you (GNU sed & bash): NEW=$(sed 's/\.//g' <<<"$OLD") or NEW=$(echo "$OLD" |

grep multiple patterns single file argument list too long

大憨熊 提交于 2021-02-08 23:41:13
问题 I am currently searching for multiple patterns in a file. The file is of 90GB in size, I am searching on a particular field(from position 6-17 in each line). I am trying to get all the lines that contain any of a particular list of numbers. The current syntax I am using is: grep '^.\{6\}0000000012345\|^.\{6\}0000000012543' somelargeFile.txt > outputFile.txt For small number of patterns this works. For a large number of patterns I get the "Argument list too long" error. One alternative I have

grep multiple patterns single file argument list too long

浪尽此生 提交于 2021-02-08 23:40:47
问题 I am currently searching for multiple patterns in a file. The file is of 90GB in size, I am searching on a particular field(from position 6-17 in each line). I am trying to get all the lines that contain any of a particular list of numbers. The current syntax I am using is: grep '^.\{6\}0000000012345\|^.\{6\}0000000012543' somelargeFile.txt > outputFile.txt For small number of patterns this works. For a large number of patterns I get the "Argument list too long" error. One alternative I have

Reasons for not using `\s` and `\S`

大城市里の小女人 提交于 2021-02-08 11:01:40
问题 In GNU sed answers using the regular expression extensions \s which matches whitespace caracters and its dual \S which matches non-whitespace characters, seem to be shied from. Why is this? 回答1: They're GNU-only and so non-portable to other seds, that's all. Just wrt matching white space and use of -E (idk about the rest), the example you referenced would work with OSX/BSD sed or GNU sed as written, but if you used \s instead of [ \t] then it'd stop working in OSX/BSD sed. Personally I'd have

Reasons for not using `\s` and `\S`

 ̄綄美尐妖づ 提交于 2021-02-08 11:01:14
问题 In GNU sed answers using the regular expression extensions \s which matches whitespace caracters and its dual \S which matches non-whitespace characters, seem to be shied from. Why is this? 回答1: They're GNU-only and so non-portable to other seds, that's all. Just wrt matching white space and use of -E (idk about the rest), the example you referenced would work with OSX/BSD sed or GNU sed as written, but if you used \s instead of [ \t] then it'd stop working in OSX/BSD sed. Personally I'd have

Reasons for not using `\s` and `\S`

試著忘記壹切 提交于 2021-02-08 10:59:56
问题 In GNU sed answers using the regular expression extensions \s which matches whitespace caracters and its dual \S which matches non-whitespace characters, seem to be shied from. Why is this? 回答1: They're GNU-only and so non-portable to other seds, that's all. Just wrt matching white space and use of -E (idk about the rest), the example you referenced would work with OSX/BSD sed or GNU sed as written, but if you used \s instead of [ \t] then it'd stop working in OSX/BSD sed. Personally I'd have