linux - Sed find,match and replace -
so have following script (just test)
#!/bin/bash file in * echo $file done and i'm trying add parenthesis around file. i'm pretending dont know full name of variable file.
cat sc.sh | sed 's/fi*/(&)/g' #!/bin/bash (f)or (fi)le in * echo $(fi)le done so i'm trying match words beginning fi , adding parenthesis around them. doing wrong? tried number of variations didn't work. can see command matches f or fi , adds parenthesis around them not whole word. why?
any appreciated.
your regex fi* looking f followed 0 or more i's. want more this:
cat tmp | sed 's/\bfi[^ ]*/(&)/g' \bfi looks word boundary (i.e. start of word) followed 'fi'. [^ ]* matches remaining (non-space) characters in word.
Comments
Post a Comment