Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8144345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:21:03+00:00 2026-06-06T13:21:03+00:00

I am trying to print a particular text using awk if string is empty.

  • 0

I am trying to print a particular text using awk if string is empty. It works fine in the below case

noob@noob:~$ echo "" | awk '{if ($0=="") print "not playing"}'
not playing

but when I try to take a similar approach in the below case it didn’t work

noob@noob:~$ mpc current | awk '{if ($0=="") print "not playing"}'
noob@noob:~$ 

I believe the output of mpc current if no song is playing is an empty string.

noob@noob:~$ mpc current
noob@noob:~$              #empty string

So, is my assumption of empty string wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:21:04+00:00Added an answer on June 6, 2026 at 1:21 pm

    Apparently it prints nothing at all, not even a newline. Try this instead.

    mpc current | awk '{ print } END { if (!NR) print "not playing" }'
    

    This prints any output. If you don’t want that, take out the { print }.

    awk processes each line in turn, and then at EOF performs any END block. If there were no input lines, there will be an EOF right at the start, the variable NR will be zero, and so the END block will print the placeholder text. (I originally had a dedicated variable for this, but the built-in line number variable NR, as used in Bob Vale’s answer, is decidedly more elegant. It is incremented for each input line that awk reads.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to retrieve particular parts of a string in a text file
I am trying to print a particular area on my webpage by using jQuery
I am trying to print a report that contains a bar graph using the
I am trying to print a portion of the page in FF3. This works
Hi I'm not particular good at Java so please bear with me. I'm trying
Im trying print Excel file data on a page. To do it i used
Im trying to print the realtime output based on user input for a search.
I'm trying to print the output of function only when it is true but
I am trying to print invoice. But top whatever i do to setting margins,
I am trying to print 1 if there are at least two of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.