質問編集履歴

4

typo

2022/04/22 01:57

投稿

noc
noc

スコア73

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- zshスクリプトにて、最終的に以下のコードを `sed -ibak -e "75,78d" -e "74,74d" -e "67,71d" ~/target` のように展開させて対象のファイルの行を削除して保存を行いたいです。
1
+ zshスクリプトにて、最終的に以下のコードを `sed -i.bak -e "75,78d" -e "74,74d" -e "67,71d" ~/target` のように展開させて対象のファイルの行を削除して保存を行いたいです。
2
2
 
3
3
  ```shell
4
4
  targetFile=~/target

3

コードタイプをbashからshell に

2022/04/22 01:00

投稿

noc
noc

スコア73

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  zshスクリプトにて、最終的に以下のコードを `sed -ibak -e "75,78d" -e "74,74d" -e "67,71d" ~/target` のように展開させて対象のファイルの行を削除して保存を行いたいです。
2
2
 
3
- ```bash
3
+ ```shell
4
4
  targetFile=~/target
5
5
  arr=($'74:74:baz\nqux' '67:71:quux' $'75:78:foo\nbar') # 各要素の先頭2フィールドが削除する行の指定
6
6
 

2

targetFileを修正

2022/04/22 00:28

投稿

noc
noc

スコア73

test CHANGED
File without changes
test CHANGED
@@ -1,7 +1,7 @@
1
1
  zshスクリプトにて、最終的に以下のコードを `sed -ibak -e "75,78d" -e "74,74d" -e "67,71d" ~/target` のように展開させて対象のファイルの行を削除して保存を行いたいです。
2
2
 
3
3
  ```bash
4
- targetFile='~/target'
4
+ targetFile=~/target
5
5
  arr=($'74:74:baz\nqux' '67:71:quux' $'75:78:foo\nbar') # 各要素の先頭2フィールドが削除する行の指定
6
6
 
7
7
  # sed に与える -e "1,2d" 形式の引数を得る

1

補足

2022/04/21 17:42

投稿

noc
noc

スコア73

test CHANGED
File without changes
test CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  ```bash
4
4
  targetFile='~/target'
5
- arr=($'74:74:baz\nqux' '67:71:quux' $'75:78:foo\nbar')
5
+ arr=($'74:74:baz\nqux' '67:71:quux' $'75:78:foo\nbar') # 各要素の先頭2フィールドが削除する行の指定
6
+
7
+ # sed に与える -e "1,2d" 形式の引数を得る
6
8
  cmds=$(
7
- for line in "${arr[@]}"; do
9
+ for line in "${arr[@]}"; do # 要素に改行が含まれた配列を要素ごとに処理させるようにする
8
10
  echo "${(q)line}"
9
11
  done | awk -F: '{printf "-e \"%d,%dd\"\n", $1, $2}' | sort -nr
10
12
  )