0

I am trying to paste two cuts in bash, but it throwing an error Syntax error: "(" unexpected when i am trying to run in loop. however the same code is working on a single file. Can anyone please help me.

this is working

paste -d,  <(cut -d, -f -2 IE3BW0047A_03012017000949.csv) <(rev IE3BW0047A_03012017000949.csv | cut -d, -f -7 | rev)

but execution in loop is not working

for filename in *.csv; do
    paste  -d , < (cut -d, -f -2 "$filename") < (rev "$filename" | cut -d, -f -7 | rev) > ${tgt_wd}/"$filename"
done
2
  • shellcheck.net Commented Mar 16, 2017 at 10:59
  • 1
    As you indicated you were using sh, POSIX shell does not recognize process substitutions. Even your /bin/sh is link to bash, it will parse <(...) as an incorrect input redirection, to maintain POSIX compatibility. Commented Mar 16, 2017 at 13:45

2 Answers 2

3

There should be no space between < and ( in process substitution:

for filename in *.csv; do
    paste  -d , <(cut -d, -f -2 "$filename") <(rev "$filename" | cut -d, -f -7 | rev) > ${tgt_wd}/"$filename"
done
Sign up to request clarification or add additional context in comments.

9 Comments

Error still exists
Did you fix it in both places?
any more ideas?
@occasionalvisitor Are you actually executing the code with bash?
How can i achieve the same functionality using python ?
|
1

I made it into tmp files and it worked.

#!/bin/bash

for filename in *.csv; do
    cut -d, -f -2 "$filename" > 1_"$filename"
    rev "$filename" | cut -d, -f -7 | rev > 2_"$filename"
    paste  -d, 1_"$filename" 2_"$filename" > "$tgt_dir"/"$filename"
    rm 1_"$filename" 2_"$filename"
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.