[SOLVED] bash suggestions to convert horizontal columns to vertical columns
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
bash suggestions to convert horizontal columns to vertical columns
I am attempting what I ~thought~ was kind of straight forward. I am pulling column data from a Windows host via bash, and the results are good but the format is not what I am trying for. Here is what I get:
As you can tell from the output, at minimum it will have two lines of return, and max will be variable based on hard drives.
I have messed with using tr and awk to break things up in a for loop, and I can make each line display vertically, however when adding the additional column output I just cannot make it work.
Any suggestions or direction would be greatly appreciated.
Thank you very much! I went with answer #3, as I was able to run it inline with the WQL query itself and datafill a base varaible. With this, I can really make something useful here! Thank you again!
Using same concept you could do that in Bash as well:
Code:
#!/bin/bash
while IFS=\| read -a LINE; do
for I in "${!LINE[@]}"; do
if [[ -n ${ARR[I]} ]]; then
ARR[I]=${ARR[I]}$'\t'${LINE[I]}
else
ARR[I]=${LINE[I]}
fi
done
done
IFS=$'\n' A="${ARR[*]}"
echo "$A"
Hmmm ... initially I would have said you missed the BEGIN ... which version of ruby are you running? Unfortunately there are a few quirks which catch me out between versions
I believe the below excerpt 'may' identify the problem:
Quote:
Ruby 1.9 introduces many significant changes over the 1.8 series.[21] Examples:
Block local variables (variables that are local to the block in which they are declared)
Unfortunately I started with 1.9 so am unsure on what is required to be changed to make it work in the older version
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.