Cloudkul Support

How to use ‘awk’ command in place of ‘grep’ and ‘cut’ commands ?

awk -F : '{ if ($<position_in_line_to_check> ~ <content_to_search>) print $<position_in_line>}' <File_Name>

For Example-:

To print name of users from /etc/passwd having /usr/sbin/nologin we can use
only awk command rather using grep and execute it as-

awk -F : '{ if ($7 ~ /nologin/) print $1}' /etc/passwd.

 

Is this article is helpful?

People like and 1 people dislike.

If result is not found or irrelevant, Please contact us.

Submit your request

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home