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.
But the result is an enumeration of every frames and every LPARS. However, I just want the first Frame with all thoses LPARS then the second frame with all thoses LPARS etc...
Your list seems to be of a consistent order and cleanly eliminated with commas. Here is a quick suggestion how this could be handled.
Code:
$ foo='FRAME_NAME1,LPAR_NAME1,25,1.0,2'
$ for i in a b c d e; do eval "$i=\"${foo%%,*}\""; foo="${foo#*,}"; done
$ echo "a = $a"
a = FRAME_NAME1
$ echo "b = $b"
b = LPAR_NAME1
$ echo "c = $c"
c = 25
$ echo "d = $d"
d = 1.0
$ echo "e = $e"
e = 2
This script works perfectly. Can you just tell me what is the $PREV variable ? I don't understand how this if condition can display one frame and his informlations bellow him !
I am sorry for the late reply and I thank you for your answers !
This script works perfectly. Can you just tell me what is the $PREV variable ? I don't understand how this if condition can display one frame and his informlations bellow him !
Thank you !
This is an example of one of the oddities of Bash: variables magically come into scope. To make it less confusing you could set $PREV to an empty string before the loop. If you're wondering what $PREV's purpose is, though, it allows the script to only print the frame names it hasn't encountered before. Basically it allows you to group frame items together.
Code:
#!/usr/bin/bash
OLDIFS=$IFS
IFS=","
PREV=""
while read FRAME LPARS RAM CPU1 CPU2; do
if [[ $FRAME != $PREV ]]; then
PREV="$FRAME"
echo -e "\e[1;33m$FRAME \
========================\e[0m\n"
fi
echo -e "LPARS : \t$LPARS\n\
RAM : \t$RAM\n\
CPU1 : \t$CPU1\n\
CPU2 : \t$CPU2\n"
done < <(sort "$1")
Last edited by individual; 07-08-2019 at 10:18 AM.
Reason: Reworded for clarity.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.