0

I am trying to convert the key value pair output of the script to csv file using the following commands.

cat config/password | ssh -tt -J support@$gateway support@$ip "$(<${base}/systemkv.sh)" 3>/dev/null | tee /tmp/log | cut -d ':' -f2 | paste -s -d ',' - | tee -a /tmp/output.csv

The above command just shows the last line or the last line overlaps with other lines.

The cut command works perfectly for the command below, but it does not allow the use of sudo command.

cat config/password | ssh -J support@$gateway support@$ip "$(<${base}/systemkv.sh)" 3>/dev/null | tee /tmp/log | cut -d ':' -f2 | paste -s -d ',' - | tee -a /tmp/output.csv

Expected Output

first:Sujit
last:Maharjan
Sujit,Maharjan

Real Output

first:Sujit
last:Maharjan
,Maharjan
2
  • 1
    When you say "overlaps with other lines" and indicate output that is missing data, the usual culprit are carriage returns in the original output. That seems to be the systemkv.sh script. The 3rd line that it outputs would be the one to focus on. – Jeff Schaller Aug 31 '20 at 16:09
  • Adding to Jeff Schaller's comment above. Try running ssh ... | od -c. That should show you the output broken down into individual characters. Compare this between the two variants of the SSH command that you have tested. – Haxiel Aug 31 '20 at 16:14
1

The culprit seems to be the carriage return character. I deleted the \r by using.

ssh ... | tr -d '\r' | ...

The command is now working perfectly.

Thanks, @Jeff Schaller and @Haxiel for your help.

1
  • You might consider putting that tr as close to the problem as possible, perhaps inside the command substitution. – Jeff Schaller Aug 31 '20 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.