AWK, SED, PRINTF?!? (Linux+ Objective 1.2.2)
Vložit
- čas přidán 27. 08. 2024
- Manipulating text is one of the things the Linux command line is really, really good at doing. Using a combination of tools, you can pretty much get any sort of formatted output from pretty much any sort of text input. In this video, we learn to use "awk", "sed", and "printf" to transform text.
This is part of our CompTIA Linux+ series, but is a good primer on using these tools whether you're prepping for the exam or not.
The Linux+ objectives are available here: snar.co/plusob...
If you'd like to look at our "Weekend Assignment", even if it's after the fact, the challenge should still be available here: snar.co/wa1
We'll go over the solution at the beginning of this week's livestream. (I'll try to remember to put a link to the stream right here afterward)
ALSO: My "other" channel, with no rules and lots of... me, is over here:
@brainofshawn
I mentioned my Patreon page, which is here:
/ shawnp0wers
And if you just can't get enough of the stuff I do, or you want to connect with other Nerdlings, most things are listed here: shawnp0wers.com
Thanks for joining us!
#Linux #CompTIA #XK0_005
Hello Shawn,
An earnest request, kindly complete the Linux+ series if you can at your earliest convenience. I have scheduled my Linux+ in early August and I'm so thankful that I found your series. I'm following you content now for my preparation.
Absolutely amazing series, thanks so much for publishing such a great content.
how did the test go?
i am also preparing the linux+ through shawn's videos. we really appriciate your effort. thank you soo much 👍💯💫
My apologies for the big delay in finishing the course, but thank you for your kind words!
Thank you very much for your videos, they are pretty few resources just for linux+, so these are really helpful. I just wanted to point out.
The `-e` flag for sed is not for extended regular expressions but for "add the script to the commands to be executed"
I don't what it means as inline sed is automatically processed without the flag but it isn't for extended regex (that's a -E flag)
Thanks Shawn! This is the series I needed! I have started studying for Linux+ and happen to stumble upon this series just in time! your explanations and examples are great! You make the material easier to digest and understand! Keep it up!
Thank YOU, that's great to hear! And hopefully with my silly 90days thing, I'll start pumping out content more frequently!!!
@@shawnp0wers is your series enough content to pass the linux + ?
And we have been waiting for it eagerly ! Thanks for being there for others like me
I appreciate the patience. Life sure does have a habit of getting in the way! :D
Fantastic video Shawn!
Love your videos Shawn! Thank you for your hard work! Please consider doing a RHSA course ! PLEASE PLEASE PLEASE 🙂
Thank you! It's one of the biggest requests I get, so... hopefully I'll finish Linux+ soon and move on to something new. Maybe RH!
awk seems good to use, sed and printf i may need abit more time to play around to get my head around - great video! great content!
Thanks! And yeah, I find AWK (and the specific use case I outlined) to be very useful. I occasionally use SED for things, but need to google it every time -- and I honestly very rarely use printf.
Fantastic work && thanks a million Shawn, I was so glad to see this video in my feed!
Glad you enjoyed it! It feels *really good* when I can record and release a new video.
This video was very helpful for my Linux+ exam
I have been using Jasion Dion training courses for bootcamps etc etc. You are 10x more interesting man. With much less resources I think you could explode
Thank for preparing the assignment Shawn! That will help a lot.
I'm glad to hear it! I'm going to keep trying to come up with useful assignments, but we'll see how well I can do...
@@shawnp0wers You are already doing great! The last assignment was epic. I learned a lot from it.
Hi Shawn! Good to see a new video again! Congratulations on becoming a grandpa! I am planning on taking the Lpic-1 101-500 Exam next month so I am excited for a new challenge again. Maybe I will take a Linux + next year but it would be just for fun :)
w00t! Good luck on the 101-500!!!
@@shawnp0wers thanks man! Thank you for making this content ! I am planning to go for it on 14.10
@@damianpodgorski6977 let me know how you get on please. I want to take it at the start of next year.
@@mason8714 sure man! I can share some tips with you if you want
@@damianpodgorski6977 that would be fantastic! Are you on shaens discord?
This is actually c programming the printf function with formatting specifier
Thanks Shawn! Ps... Thanks also for such inspiring podcasts!
Whoa, thank you AGAIN!
I'm pretty excited about the silly 90days thing too, should get me in the groove of releasing videos without overthinking (as much). :)
I'd love to see you do a more detailed video on awk.
No promises, but there's certainly plenty of material. AWK is... so powerful. :)
Thanks!
You bet!
Good video Shawn. My brain had already exploded. I have tried to read the book on AWK by the authors of the language. Great book but dense. It is called, The AWK programming language by: Auru:o V. AHo BRIAN W. KERNIGHAN PETER J. WEINBERGER, I found it as a pdf online. Published in the 70S but still just as good as the day it was written. Thanks again for the video.
Thanks! Yeah, it was tough to decide an appropriate "depth" for each tool. Ironically, while AWK is probably the most complex and powerful, it was the one I chose to go least into. Still, my hope is that we covered enough for what the Linux+ might throw at someone. :)
Shawn, you are a god!
You rock my tiny little brain, again...!
Many, many thanks!
P.S. god with a capital "G" is not allowed..
Thank you! And I'm not even sure I qualify for lower-case "g" god, but for SURE not a capital! :D
Thanks for your hard work!
where is your other channel? you said you would post a link
Thanks for this! One problem I'm looking into though --- { printf "%f
" 43.7 } gives me invalid number!
aaaaand I figured it out 10 seconds later --- I noticed my system is set up with commas for decimals, so 43,7 did the trick! heads-up to euroland.
sed is like vi? cool
can you add padding to printf string on the Left AND Right side? so something like :
printf "%10s
" text
will add 10 spaces padding to the LEFT side, but can you simulataneously add some space to the right as well?
actually dont mind, I just figured it as I typed the comment lol:
printf "[%10s%-10s]" text
[ text ]
so if you give it one text argument any consequent %s you add in the formula will refer to the same outputted variable
I didn’t know the answer, so thanks for testing! :)
so heres some more shenningans. you can mix the %s and %d for the same variable! see my consequent comment:
printf "[%-10s]
%s
" here "not here"
[here ]
not here
The hair … 😂
hehehehe :D
Why not just sed '/^#/d' instead of using 2 seds? That lets you keep some of the visual break ups for readability. The -e is extraneous there as well as you're only using one pattern at a time. The -e is for if you want to do two things. You can chain the -e without having to pipe to another sed:
sed -e '/^#/d' -e '/^$/d' file.conf
I didn't realize you could chain two substitutions with one command, cool!
And as far as why one way over another... it's always so challenging to decide what will make the basics easier to understand. Plus, I don't use sed often enough to make the best choices, truth be told. But thanks for the info -- I love when I get to learn stuff I didn't know! :)