LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-22-2020, 03:31 PM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
awk split shows nothing


Can anyone help me to understand why this works?
Code:
df -h | awk '/Mounted on/{ split($6,a," "); print a[1]}'
Mounted
But this outputs nothing?
Code:
df -h | awk '/Mounted on/{ split($6,a," "); print a[2]}'
I would have expected to show 'on'.
This, on the other hand, works, if applied on the whole line:
Code:
df -h | awk '/Mounted on/{ split($0,a," "); print a[7]}'
on
 
Old 04-22-2020, 03:39 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
If you print $6 you will see just the single word, "Mounted". How would you expect splitting $6 to reveal anything else?
 
1 members found this post helpful.
Old 04-22-2020, 04:03 PM   #3
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Yes, I guess that was the reason why I posted in the newbie section. Thanks
 
  


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
Kali linux shows blank screen while installling and nothing shows after dhireshartron Debian 2 07-13-2018 06:40 AM
[SOLVED] sed inside awk or awk inside awk maddyfreaks Linux - Newbie 4 06-29-2016 01:10 PM
[SOLVED] Once again... awk.. awk... awk shivaa Linux - Newbie 13 12-31-2012 04:56 AM
package management (to split or not to split packages) frischi Linux - Desktop 2 05-06-2010 03:15 PM
How to split file , .. awk or split ERBRMN Linux - General 9 08-15-2006 12:02 AM

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

All times are GMT -5. The time now is 07:26 PM.

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