LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-04-2019, 09:58 PM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Rep: Reputation: 0
Unhappy How to tweak output by awk to make an array?


Hey Guys,

I am using az vm list command to list all host which have been provisioned so far like below:

Code:
az vm list --output=table|grep NXT|awk '{ print $1}'
NXTPREPAOS-1
NXTPREPAOS-2
NXTPREPAOS-3
NXTPREPAOS-4
NXTPREPAOS-5
NXTPREPSQL-1
NXTPREPSQL-2

Instead, I want to have something like this
"NXTPREPAOS-1" "NXTPREPAOS-2" "NXTPREPAOS-3" etc

Possible to achieve it easily?
The reason being, I can use it as an array straight away and perform operations on the array, how to achieve it.

Kindly assist.


Thanks
 
Old 03-04-2019, 10:36 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
This should be in your other thread, not forked into another with no detail.

Attack the problem, not a symptom - fix the array assignment in your script.
 
Old 03-04-2019, 10:38 PM   #3
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
Ok, sometimes people prefer separate thread hence I created here, more than happy to get it married with other thread.
 
Old 03-05-2019, 12:39 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
As a note to anyone coming across this thread:

- the grep is not needed as awk can already do this

- assuming you are talking a bash array, it uses IFS variable when looking at items to assign to an array, so new lines are not a problem

Code:
array=($(az vm list --output=table | awk '/NXT/{print $1}'))
 
1 members found this post helpful.
Old 03-05-2019, 07:11 AM   #5
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
@grail, that's awesome. Thank you so much matey
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed inside awk or awk inside awk maddyfreaks Linux - Newbie 4 06-29-2016 01:10 PM
BASH-Adding array element: Naming issue using array[${#array[*]}]=5 calvarado777 Programming 8 07-26-2013 09:48 PM
LXer: How to Tweak And Perfect The Unity Desktop With Unity Tweak Tool Linux/Ubuntu LXer Syndicated Linux News 0 04-04-2013 08:51 PM
[SOLVED] Once again... awk.. awk... awk shivaa Linux - Newbie 13 12-31-2012 04:56 AM
bash: use file as input into array, parse out other variables from array using awk beeblequix Linux - General 2 11-20-2009 10:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration