0

I have 2 files in Linux like below

file1

test_1
test_3
test_5
test_6

file2

test_1,smoke_test
test_2,rain_test
test_3,sun_test
test_4,wind_test

I want to compare these two files and delete the tables in file1 that are present in file2 that is the first part before comma(,)

Output required:

file3

test_5
test_6

I have tried like below

grep -v -Ff <(cut -d',' -f1 file2) file1 >file3

I got what I want.

Now when I write a script It throws an error

new.sh: line 67: syntax error near unexpected token `('

Script

#!/bin/bash

grep -v -Ff <(cut -d',' -f1 file2) file1 >file3

I'm running it with:

sh -x script.sh
Barmar
  • 741,623
  • 53
  • 500
  • 612
User12345
  • 5,180
  • 14
  • 58
  • 105

1 Answers1

2

You're running the script using sh rather than bash, so you're not getting the bash extensions like <(...) process substitution. Run it with:

bash -x script.sh

or just:

./script.sh

The latter will use the interpreter named in the #! line.

Barmar
  • 741,623
  • 53
  • 500
  • 612