Question: I have a table t1 with a 'foo' column, and records containing 'bar' and 'baz' in column 'foo'. I also have a table t2 with columns 'bar', 'baz' and 'quux'. I want to do something like the following:

```
SELECT (SELECT foo from t1) FROM t2;

```

that is, get the two column names from t1 and query those columns of t2. If I try to do this with MonetDB, I get an error message:

```
cardinality violation (2>1)

```

so,

* is there some other way to do this with MonetDB?
* is this possible in MySQL? other DBMSes?

Example queries (or non-query directives followed by a query) are welcome.

Answer: 
```
$ sed '/()\s*{/{N; s/.*MARKERFUNCTION/== Text to add ==\n\0/}' file.c 
void foo () {
  bar();
}

== Text to add ==
void example () {
  MARKERFUNCTION();
  ...
}

```

* `/()\s*{/` match `()` followed by any spaces and `{` - to detect line with function.. if there can be content inside `()`, using `/)\s*{/` could work
* `{N;` if above condition matches, get next line
* `s/.*MARKERFUNCTION/== Text to add ==\n\0/` perform substitution by checking if the pattern `MARKERFUNCTION` is there in the two lines we have. Then in replacement section, add the required text, a newline and the pattern matched which by default is in `\0`

`awk` solution, assuming there is a blank line prior to start of function having the required pattern

```

$ awk -v RS= -v ORS="\n\n" '/MARKERFUNCTION/{$0 = "--Text to add--\n" $0} 1' file.c
void foo () {
  bar();
}

--Text to add--
void example () {
  MARKERFUNCTION();
  ...
}

```

This reads the input file paragraph wise and if a paragraph contains the required pattern, add a line before printing
Using `tac` with `awk`:

```
tac file.c | awk '/MARKERFUNCTION/{p=NR} p && NR==p+2{print "new line added"} 1' | tac

void foo () {
  bar();
}

# <- I want a line to be added here!
new line added
void example () {
  MARKERFUNCTION();
  ...
}

```