sed

Escaping double quotation marks in sed

依然范特西╮ 提交于 2021-02-08 10:28:24
问题 Creating a search and replace function for my application, I am running a test scenario with 3 files, array tscript test I am trying to escape double quotation marks but it wont work script file contains variableName=$1 sed "s#data\-field\=\"${variableName}\.name\"#data\-field\=${variableName}\.name data\-type\=dropdown data\-dropdown\-type\=${variableName}#g" test test file contains data-field=“fee_category.name” data-field=“tax_type.name” array file contains fee_category tax_type There is

sed: remove whole words containg a character class

蓝咒 提交于 2021-02-08 08:20:18
问题 I'd like to remove any word which contains a non alpha char from a text file. e.g "ok 0bad ba1d bad3 4bad4 5bad5bad5" should become "ok" I've tried using echo "ok 0bad ba1d bad3 4bad4 5bad5bad5" | sed 's/\b[a-zA-Z]*[^a-zA-Z]\+[a-zA-Z]*\b/ /g' 回答1: Using awk : s="ok 0bad ba1d bad3 4bad4 5bad5bad5" awk '{ofs=""; for (i=1; i<=NF; i++) if ($i ~ /^[[:alpha:]]+$/) {printf "%s%s", ofs, $i; ofs=OFS} print ""}' <<< "$s" ok This awk command loops through all words and if word matches the regex /^[[

Replace blank fields with zeros in AWK

跟風遠走 提交于 2021-02-08 05:59:00
问题 I wish to replace blank fields with zeros using awk but when I use sed 's/ /0/' file, I seem to replace all white spaces when I only wish to consider missing data. Using awk '{print NF}' file returns different field numbers (i.e. 9,4) due to some empty fields input 590073920 20120523 0 M $480746499 CM C 500081532 SP 501298333 0 M *BB 501666604 0 M *OO 90007162 7 M +178852 90007568 3 M +189182 output 590073920 20120523 0 M $480746499 CM C 500081532 SP 501298333 0 0 M *BB 0 0 0 0 501666604 0 0

Can't figure out how to implement REGEX with AppleScript

半城伤御伤魂 提交于 2021-02-08 04:00:32
问题 I wrote a regex command to find and output the first instance of a line of digits in a string: find: ^[^\d]*(\d+).* replace: $1 The problem is that in order to actually utilize this in AppleScript, the only way I know of doing this is with calling a shell script and using sed. I can't figure out how to actually use my regex in this way. I've tried for hours without any luck. This is as close as I can get, but it returns ALL the numbers in a string, rather than the first group of numbers: set

Remove duplicate filename extensions

不羁岁月 提交于 2021-02-08 03:50:21
问题 I have thousands of files named something like filename.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz I am using the find command like this find . -name "*.gz*" to locate these files and either use -exec or pipe to xargs and have some magic command to clean this mess, so that I end up with filename.gz Someone please help me come up with this magic command that would remove the unneeded instances of .gz . I had tried experimenting with sed 's/\.gz//' and sed 's/(\.gz)//' but they do not seem to work (or to

Remove duplicate filename extensions

こ雲淡風輕ζ 提交于 2021-02-08 03:49:48
问题 I have thousands of files named something like filename.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz I am using the find command like this find . -name "*.gz*" to locate these files and either use -exec or pipe to xargs and have some magic command to clean this mess, so that I end up with filename.gz Someone please help me come up with this magic command that would remove the unneeded instances of .gz . I had tried experimenting with sed 's/\.gz//' and sed 's/(\.gz)//' but they do not seem to work (or to

Remove duplicate filename extensions

倖福魔咒の 提交于 2021-02-08 03:49:37
问题 I have thousands of files named something like filename.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz.gz I am using the find command like this find . -name "*.gz*" to locate these files and either use -exec or pipe to xargs and have some magic command to clean this mess, so that I end up with filename.gz Someone please help me come up with this magic command that would remove the unneeded instances of .gz . I had tried experimenting with sed 's/\.gz//' and sed 's/(\.gz)//' but they do not seem to work (or to

Interweave two files bash script

浪尽此生 提交于 2021-02-08 02:15:29
问题 I am trying to interweave two files that contain one sentence per line. I double spaced ( sed G ) the first file and I would like to incorporate the content of the second file into those empty lines. How can I interweave both files so that the 1st line of file B goes below the 1st line in file A, the 2nd line of file B below the 2nd line of file A, until it reaches the end ? Example: [line number|sentence number|sentence] 1 1 fileA 2 3 2 fileA 4 5 3 fileA 6 7 4 fileA Expected result: 1 1

Interweave two files bash script

依然范特西╮ 提交于 2021-02-08 02:11:22
问题 I am trying to interweave two files that contain one sentence per line. I double spaced ( sed G ) the first file and I would like to incorporate the content of the second file into those empty lines. How can I interweave both files so that the 1st line of file B goes below the 1st line in file A, the 2nd line of file B below the 2nd line of file A, until it reaches the end ? Example: [line number|sentence number|sentence] 1 1 fileA 2 3 2 fileA 4 5 3 fileA 6 7 4 fileA Expected result: 1 1

Print rows with condition on field data

天涯浪子 提交于 2021-02-07 20:18:36
问题 I have file with data cell input out type fun level AI20 A1,A2 Z comb ((A1A2)) 2 IA2 A1,A2,A3 Z comb ((!A1A2)A3) 3 XOR A1,A2,B1 Z comb (((A1A2)B1) 3 IAD A1,A2,A3 Z comb (!((A1A2)A3)) 3 INV I1 ZN comb (!I1) 1 BUF A1,A2,A3,B1 Z comb (!(((A1A2)A3)B1)) 4 From this data, I want to print rows whose level field (6th column) gives sum 7 together. here to get level sum 7 we can select AI2O , BUF , INV rows giving level sum as 2 + 4 + 1 = 7 and print them Or can select XOR , IAD , INV giving sum 3 + 3