Take name of input file to give the name of output file

Hello everyone,

I think this would be easy for you experts.

Refering the suggestion that Scrutinizer gave me in this thread Transpose info that is within blocks Post: 302612499

I have the script in this form

awk '{$1=$1}1' "$1" | awk ' ...'

Where "$1" takes the value of "inputfile" then I can run my script in this way:

. Script.sh fileXY.txt > output.txt

I only would like to have the name of output equal to the basename of input and send only the script like this:

. Script.sh fileXY.txt

and get the output file named automatically fileXY.csv.

I've put at the beginning of the script this:

Input="$1"
Output=basename $Input .txt
awk '{$1=$1}1' "$1" | awk ' ...' ' RS= OFS=\| > $Output

But is not working.

I hope makes sense and somebody could help me with this.

Thanks in advance

Try:

Output=${Input%.*}.csv

instead of:

Output=basename $Input .txt