programing

표준 입력에서 sed를 읽으려면 어떻게 해야 합니까?

css3 2023. 4. 15. 09:09

표준 입력에서 sed를 읽으려면 어떻게 해야 합니까?

난 노력하고 있다.

grep searchterm myfile.csv | sed 's/replaceme/withthis/g'

그리고 얻는 것

unknown option to `s'

내가 뭘 잘못하고 있지?

편집:

코멘트에 의하면, 코드는 실제로 올바른 것입니다.내 전체 코드는 다음과 같았다.

grep searchterm myfile.csv | sed 's/replaceme/withthis/g'
# my comment

그리고 어떤 이유에서인지 제 코멘트가 sed에 입력된 것 같습니다.정말 이상하다.

--information 옵션을 사용합니다.

grep searchterm myfile.csv | sed --expression='s/replaceme/withthis/g'

sed-ion을 지정하려면 "-e"를 사용합니다.

cat input.txt | sed -e 's/foo/bar/g'

만들기 위해서sed파일 대신 stdin에서 catch를 사용해야 합니다.-e.

다음과 같이 합니다.

curl -k -u admin:admin https://$HOSTNAME:9070/api/tm/3.8/status/$HOSTNAME/statistics/traffic_ips/trafc_ip/ | sed -e 's/["{}]//g' |sed -e 's/[]]//g' |sed -e 's/[\[]//g' |awk  'BEGIN{FS=":"} {print $4}'

파일 내에서 텍스트를 인플레이스 업데이트하려고 한다면, 내 생각에는 이것이 훨씬 더 쉽게 추론할 수 있습니다.

grep -Rl text_to_find directory_to_search 2>/dev/null | while read line; do  sed -i 's/text_to_find/replacement_text/g' $line; done

  1. 다음을 사용하여 파일을 엽니다.vi myfile.csv
  2. 누르다
  3. 유형:%s/replaceme/withthis/
  4. 유형:wq를 누릅니다.

이제 파일에 새로운 패턴이 표시됩니다.

언급URL : https://stackoverflow.com/questions/9984748/how-do-i-get-sed-to-read-from-standard-input