Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- myFunction (line0
- line1
- line2
- line3
- line4)
- myFunction ( )
- $ awk '$0~/[(]/,$0~/[)]/{gsub(/line/,"newline")};1' input.txt
- another line
- something else
- myFunction (newline0
- newline1
- whatever
- newline2
- newline3
- newline4)
- some other line
- $ cat input.txt
- another line
- something else
- myFunction (line0
- line1
- lilne2
- line3
- line4)
- some other line
- $ ./edit_function_args.py input.txt
- another line
- something else
- myFunction (newline0
- newline1
- newline2
- newline3
- line4)
- some other line
- #!/bin/bash
- # Use shell builtins, read, true, false, printf
- flag=false
- while IFS= read -r line
- do
- case "$line" in
- (*"("*) flag=true ;;
- esac
- if $flag
- then
- line=${line//line/newline}
- fi
- printf "%sn" "$line"
- case "$line" in
- (*")"*) flag=false ;;
- esac
- done < "$1"
- $ perl -0777 -pe 's/([^)]+)/$&=~s|line|newline|gr/ge' ip.txt
- myFunction (newline0
- newline1
- newline2
- newline3
- newline4)
- sed '/(/,/)/s/line/newline/g'
- sed -e '/(/{' -e ':loop;s/(.*)/()/;t;N;b loop' -e '}'
- sed -e '/(/{
- :loop
- s/(.*)/()/
- t
- N
- b loop
- }'
- awk '
- function mysub(str) {
- if (str) gsub(/line/, "newline", str); return str
- }
- BEGIN {
- OFS=FS="("
- }
- NF>1 {
- if (FS=="(") {
- print $1,mysub($2); OFS=FS=")"
- } else {
- print mysub($1),$2; OFS=FS="("
- }
- next
- }
- {
- print FS=="(" ? $0 : mysub($0)
- }' /path/to/input
- awk 'function m(s){gsub(/line/,"newline",s);return s}BEGIN{OFS=FS="("}NF>1{if(FS=="("){print $1,m($2);OFS=FS=")"}else{print m($1),$2;OFS=FS="("}next}{print FS=="("?$0:m($0)}' /path/to/input
- line96
- line97 myFunction (line0
- line1
- line2
- line3
- line4) line98
- line99
- line96
- line97 myFunction (newline0
- newline1
- newline2
- newline3
- newline4) line98
- line99
- awk '
- BEGIN {
- OFS=FS="("
- }
- NF>1 {
- if (FS=="(") {
- print $1,""; OFS=FS=")"
- } else {
- print "",$2; OFS=FS="("
- }
- next
- }
- FS=="("' /path/to/input
- line96
- line97 myFunction (
- ) line98
- line99
- $ cat d.txt
- myOtherFunction (x as boolean
- y as integer
- d as string
- e as whatever)
- myFunction (xx as boolean
- yy as integer
- dd as string
- ee as whatever)
- $ cat d2.txt
- BrandNewFunction (xxx as integer
- yyy as boolean
- ddd as integer
- eee as whatever)
- $ a="$(sed -n '/myFunction (/,/)/p' d.txt)" #isolates myFunction from the source file d.txt
- $ b="$(cat d2.txt)" #get contents of file d2.txt (BrandNewFunction)
- $ c="$(cat d.txt)" #get the whole source file d.txt
- $ echo "${c/$a/$b}" #in source file d.txt ($c) replace $a with $b (d2.txt)
- #Output:
- myOtherFunction (x as boolean
- y as integer
- d as string
- e as whatever)
- BrandNewFunction (xxx as integer
- yyy as boolean
- ddd as integer
- eee as whatever)
- $ a="$(sed -n '/myFunction (/,/)/p' d.txt)";b="$(cat d2.txt)";c="$(cat d.txt)";echo "${c/$a/$b}"
- $ b="$(sed -n '/BrandNewFunction (/,/)/p' d2.txt)"
- $ b="myFunction ( )"
- sgrep -o '%r ' '(start .. end) extracting ("("__")")' < input_file
- myFunction (line0
- line1
- (line2)
- line3
- line4)
- anotherFun (x y)
- myFunction ( )
- anotherFun ( )
- sed -z 's/([^)]*)/( )/g' inputfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement