LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-10-2017, 10:11 AM   #1
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Rep: Reputation: Disabled
Thumbs up awk basic script layout


Hello, I'm trying to figure out if i'm understanding this awk script correctly.

I have:
SS = 6 {
while(getLine line<"/etc/username") {
}
}
{
print $0
}

The SS=6 is a user defined variable and the pattern block
The while(x) is a user defined function
The bottom portion of the script with the print $0 does NOT have a pattern, or also known as empty/null pattern
The $0 at the end is also a script

is this correct?
 
Old 12-10-2017, 12:38 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,836

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
no, that is not correct. Would be nice to see the whole script, not only parts.
Code:
SS = 6
the meaning of this depends on the location of it. It can be a simple assignment (set the variable SS to 6), or a mistyped check (if SS was equal to 6) - but that should be written with two =. In that case
Code:
SS == 6
may mean (similar to patterns) to execute the block { whatever } only if condition was met (so SS is equal to 6).
while is a keyword, and it is not a user defined function. getline is a built-in function.
Code:
print $0
is a line of code, means print the actual line ($0 is not a script, but the current line - which is actually processed by this awk script).

You ought to read some documentation about this, it is very well explained.
https://www.linuxquestions.org/quest...9/#post5791504

Last edited by pan64; 12-10-2017 at 12:41 PM.
 
1 members found this post helpful.
Old 12-10-2017, 10:47 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would suggest reading the manual as at present you do not understand awk at all.
 
1 members found this post helpful.
Old 12-11-2017, 01:03 AM   #4
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Question

Quote:
Originally Posted by goofygoober View Post
Hello, I'm trying to figure out if i'm understanding this awk script correctly.

I have:
SS = 6 { --> begin
while(getLine line<"/etc/username") { -->while loop begin
} --> while loop ends

} -->close

{ --> begin
print $0
} -->close

The SS=6 is a user defined variable and the pattern block
The while(x) is a user defined function
The bottom portion of the script with the print $0 does NOT have a pattern, or also known as empty/null pattern

The $0 at the end is also a script (It's not a script it is just another code block)

is this correct?
I think you should give us the whole script. And learn the fundamentals if you want to go a long way, diving into it is good but as things get complex it will be very hard if you don't know the basic.

Last edited by JJJCR; 12-11-2017 at 01:04 AM. Reason: edit
 
1 members found this post helpful.
Old 12-11-2017, 03:36 PM   #5
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by pan64 View Post
no, that is not correct. Would be nice to see the whole script, not only parts.
Code:
SS = 6
the meaning of this depends on the location of it. It can be a simple assignment (set the variable SS to 6), or a mistyped check (if SS was equal to 6) - but that should be written with two =. In that case
Code:
SS == 6
may mean (similar to patterns) to execute the block { whatever } only if condition was met (so SS is equal to 6).
while is a keyword, and it is not a user defined function. getline is a built-in function.
Code:
print $0
is a line of code, means print the actual line ($0 is not a script, but the current line - which is actually processed by this awk script).

You ought to read some documentation about this, it is very well explained.
https://www.linuxquestions.org/quest...9/#post5791504
Oh, thanks for the reply! For some reason I didn't get any alerts through email for the replies on this post.
There is no other code that comes with this, I have only this snippet and need to understand what is what.

I have taken the time to learn some more fundamentals, thanks for the replies!
 
  


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
How can I check in script that what layout is set? kaya Linux - Software 3 02-07-2015 05:09 AM
[awk script] Help me delete lines in a file using script ? sieukid Programming 5 03-20-2012 01:23 PM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 09:06 PM
[SOLVED] Awk question (but could use other basic unix command) r0tty Programming 18 05-13-2011 11:44 AM
Basic Network layout help with MASQ please SprinterPD Linux - Networking 0 03-27-2002 01:45 PM

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

All times are GMT -5. The time now is 04:06 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