Question: I want to remove duplicated columns/fields on the same row only. I tried, but I ended up with a long code with nest loops, conditions and arrays that doesn't work correctly.

* input data:

```
1 2 3 4
1 2 3 1
1 2 1 3
4 4 3 2
3 3 3 2
1 1 1 1
5 2 2 7

```
* desired output:

```
1 2 3 4
1 2 3 
1 2 3
4 3 2
3 2
1
5 2 7

```

Answer: 
The `print` statement in `awk` takes one of three forms:

* `print > expression`
* `print >> expression`
* `print | expression`

... where the `>`, `>>`, and `|` bit, and the `expression` that follows, are optional.

The `print > expression` command will cause the output to go to a file named by whatever string that `expression` evaluates to. If the file exists, it will be truncated (emptied). This is similar to how output redirection in the shell works, but the file will not be truncated by executing the same `print` statement a second time, unless `close(expression)` is used to close the file related to `expression` first.

The `>>` and `|` forms of the `print` command are also inspired by how the shell handles these tokens but see an `awk` manual for further information about these forms.

In your code, you have

```c
print 3 > 5 ? "Hello" : "World"

```

This matches the `print > expression` syntax and would therefore output the string `3` to a file called `5`. The rest of that line continues with a question mark, which your `awk` can't make much sense out of, so it complains about it. Some `awk` implementations would use the `5 ? "Hello" : "World"` bit as the `expression` and would therefore write `3` to a file called `Hello` (since `5` is a *true* value when used as a boolean).

What you most likely wanted to do is

```c
print ( 3 > 5 ? "Hello" : "World" )

```

or

```c
print ( 3 > 5 ) ? "Hello" : "World"

```

This ensures that the `print > expression` syntax isn't triggered.
Your code has an unparenthesized ternary expression [possibly] on the right side of output redirection. There are 2 issues with that:

* An unparenthesized expression on the right side of output (or input)
redirection is undefined behavior per POSIX so never do that.
* An uparenthesized ternary expression is harder to read than one with
parentheses and can lead to syntax errors in some awks in some
contexts so never do that either.

Bad:

```
print > foo bar
getline < foo bar
str = x>y ? foo : bar

```

Good:

```
print > (foo bar)
getline < (foo bar)
str = (x>y ? foo : bar)

```

When creating multiple output files, though, it's usually a good idea to close them as you go and then you would store the output file name that's the result of the expression in a variable and then you don't need parens, e.g.:

```
out = foo bar
print > out
close(out)

```

So your code:

```
awk 'BEGIN{print 3<5 ? "Hello" : "World"}'
awk 'BEGIN{print 3>5 ? "hello" : "world"}'
awk 'BEGIN{print 5<3 ? "Hello" : "World"}'

```

which, depending on what it's supposed to do, is either not using parens on the right side of output redirection or not using parens around a ternary or both and so should instead be written as:

```
awk 'BEGIN{print (3<5 ? "Hello" : "World")}'
awk 'BEGIN{print (3>5 ? "hello" : "world")}'
    or, less likely, awk 'BEGIN{print 3 > (5 ? "hello" : "world")}'
awk 'BEGIN{print (5<3 ? "Hello" : "World")}'

```