sed

Replace text in a file using sed on windows

守給你的承諾、 提交于 2020-07-23 03:52:18
问题 I am trying to replace a string in a .ism file using the SED command but it is failing for me. The line in the file is the product version which I want to change in every build. <row><td>ProductVersion</td><td>1.0.0</td><td/></row> And here is the command I'm trying: c:\rt_cygwin\bin\sed -i -r "s/ProductVersion\\"+[0-9].+[0-9].+[0-9] /ProductVersion\"1.0.%BUILD_NUMBER%/" "D:\lm.ism" Thanks 回答1: c:\rt_cygwin\bin\sed -i -r "s/ProductVersion</td>[0-9].[0-9].[0-9]/ProductVersion 1.0.%BUILD_NUMBER

Replace text in a file using sed on windows

牧云@^-^@ 提交于 2020-07-23 03:51:07
问题 I am trying to replace a string in a .ism file using the SED command but it is failing for me. The line in the file is the product version which I want to change in every build. <row><td>ProductVersion</td><td>1.0.0</td><td/></row> And here is the command I'm trying: c:\rt_cygwin\bin\sed -i -r "s/ProductVersion\\"+[0-9].+[0-9].+[0-9] /ProductVersion\"1.0.%BUILD_NUMBER%/" "D:\lm.ism" Thanks 回答1: c:\rt_cygwin\bin\sed -i -r "s/ProductVersion</td>[0-9].[0-9].[0-9]/ProductVersion 1.0.%BUILD_NUMBER

Improving performance when using jq to process large files

守給你的承諾、 提交于 2020-07-21 03:14:07
问题 Use Case I need to split large files ( ~5G ) of JSON data into smaller files with newline-delimited JSON in a memory efficient way (i.e., without having to read the entire JSON blob into memory). The JSON data in each source file is an array of objects. Unfortunately, the source data is not newline-delimited JSON and in some cases there are no newlines in the files at all. This means I can't simply use the split command to split the large file into smaller chunks by newline. Here are examples

Mutiline delete in FreeBSD

荒凉一梦 提交于 2020-07-21 03:10:10
问题 How can we make this work in FreeBSD? Multiple line delete block containing a pattern in FreeBSD. sed '/{START-TAG/{:a;N;/END-TAG}/!ba};/ID: 222/d' data.txt See sed multiline delete with pattern. 回答1: In FreeBSD sed , you can't separate commands using a semi-colon. However, you may use -e chained commands: sed -e '/{START-TAG/{' -e :a -e N -e '/END-TAG}/!ba' -e '}' -e '/ID: 222/d' file > outputfile To save the contents inline, use sed -i '' -e '/{START-TAG/{' -e :a -e N -e '/END-TAG}/!ba' -e

Mutiline delete in FreeBSD

拜拜、爱过 提交于 2020-07-21 03:09:57
问题 How can we make this work in FreeBSD? Multiple line delete block containing a pattern in FreeBSD. sed '/{START-TAG/{:a;N;/END-TAG}/!ba};/ID: 222/d' data.txt See sed multiline delete with pattern. 回答1: In FreeBSD sed , you can't separate commands using a semi-colon. However, you may use -e chained commands: sed -e '/{START-TAG/{' -e :a -e N -e '/END-TAG}/!ba' -e '}' -e '/ID: 222/d' file > outputfile To save the contents inline, use sed -i '' -e '/{START-TAG/{' -e :a -e N -e '/END-TAG}/!ba' -e

How to change the first occurrence of a line containing a pattern?

∥☆過路亽.° 提交于 2020-07-20 07:33:11
问题 I need to find the line with first occurrence of a pattern, then I need to replace the whole line with a completely new one. I found this command that replaces the first occurrence of a pattern, but not the whole line: sed -e "0,/something/ s//other-thing/" <in.txt >out.txt If in.txt is one two three four something five six something seven As a result I get in out.txt: one two three four other-thing five six something seven However, when I try to modify this code to replace the whole line, as

Rename files using sed and mv

核能气质少年 提交于 2020-07-18 04:06:22
问题 I want to rename files in the format: img_MM-DD-YY_XX.jpg img_MM-DD-YY_XXX.jpg to: newyears_YYYY-MM-DD_XXX.jpg Where: YYYY = year MM = month DD = day XXX or XX = photo number I came up with this script but it isn't working: for filename in ?*.jpg; do newFilename=$(echo $filename | \ sed 's/img_\(.*\)-\(.*\)-\(.*\)_\([0-9][0-9]\)\./newyears_20\3-\1-\2_0\4./; s/img_\(.*\)-\(.*\)-\(.*\)_\([0-9][0-9][0-9]\)/newyears_20\3-\1-\2_\4/' -) mv $filename $newFilename done Any help would be greatly

sed retrieve part of line

醉酒当歌 提交于 2020-07-16 07:50:35
问题 I have lines of code that look like this: hi:12345:234 (second line) How do I write a line of code using the sed command that only prints out the 2nd item in the second line? My current command looks like this: sed -n '2p' file which gets the second line, but I don't know what regex to use to match only the 2nd item '12345' and combine with my current command 回答1: Could you please try following, written and tested with shown samples in GNU sed . sed -n '2s/\([^:]*\):\([^:]*\).*/\2/p' Input

sed retrieve part of line

浪尽此生 提交于 2020-07-16 07:50:29
问题 I have lines of code that look like this: hi:12345:234 (second line) How do I write a line of code using the sed command that only prints out the 2nd item in the second line? My current command looks like this: sed -n '2p' file which gets the second line, but I don't know what regex to use to match only the 2nd item '12345' and combine with my current command 回答1: Could you please try following, written and tested with shown samples in GNU sed . sed -n '2s/\([^:]*\):\([^:]*\).*/\2/p' Input

UNIX Bash - Removing double quotes from specific strings within a file

淺唱寂寞╮ 提交于 2020-07-09 03:55:07
问题 Apologies if I've formatted this terribly as I've not posted here before. I'm attempting to edit a file to remove double quotation marks that are wrapped around multiple strings of varied lengths. Some of these strings include capitalisation and white-space, normally I would just use a global search and replace, however, some of the strings CAN'T have the double quotes removed as they're required. An extract of the file in question is here: "tplan"."external_plan_ref" "Plan ID", 'CMP' CMP,