0

I have a file that looks like this

# ... stuff

@late()
def test1():
    # ...

@late()
def test2():
    # ...

I need to get each match after the @late() line and do some work on them.

I've tried getting the line after using awk '/^@late()/{getline; print}' $the_file_path. The results are correct but when I iterate over the matches

for line in `awk '/^@late()/{getline; print}' $the_file_path`
do
    echo $line
done

I get

def
test1():
def
test2():

As you can see, the "def test1()" and "def test2()" are split at the " ".

Desired print output

def test1():
def test2():

I've tried surrounding each line in quotes to prevent it from breaking at the space but have had no luck. Can I get a pointer on how to handle this case?

ColinKennedy
  • 131
  • 3
  • 3
    Does this answer your question? [How to loop over the lines of a file?](https://unix.stackexchange.com/questions/7011/how-to-loop-over-the-lines-of-a-file). Read also: [Why does my shell script choke on whitespace or other special characters?](https://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters) – pLumo Feb 25 '21 at 07:26
  • Use process substitution like: `while IFS= read -r line; do ... done < <(awk ...)` – pLumo Feb 25 '21 at 07:28
  • 2
    What do you mean by "to do some work on them"? Do you want to change them or extract them? If you're extracting them, you can't really change them and then easily put them back in. – Kusalananda Feb 25 '21 at 07:29
  • As noted by @Kusalananda, please edit your question to include the desired output so contributors can understand what you are trying to achieve. – AdminBee Feb 25 '21 at 08:30

0 Answers0