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 9022801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:36:29+00:00 2026-06-16T05:36:29+00:00

The shell script below is test.sh, currently it is able to check for the

  • 0

The shell script below is test.sh, currently it is able to check for the 10th to 15th character equals to ‘000000’. However it should also check for ‘ ‘ 6 null spaces as well as empty file. Question is:
1) How to check for empty file?

filename=$1

extracted=`head -1 $filename | cut -c10-15`

if [ $extracted -eq '000000' ] ###how to check for '      ' 6 null character with or operator?
then 
mv $filename new.$filename
fi

e.g.
Input file:

Case 1 (some characters before and after the 6 zeros 000000) truefile.txt:

123456789000000161718

Case 2 (empty file) trueemptyfile.txt:

"there's nothing in this file. Empty. "

Case 3 (Some characters before and after ‘ ‘ 6 null characters) truepartialempty.txt

123456789      16171819

Thank you

And one more thing all these file is under /temp folder

/temp> ls

 test.sh truefile.txt trueemptyfile.txt truepartialempty.txt

How to run test.sh to check for all the files. thank you.

Is it?

 sh test.sh *.*
  • 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-16T05:36:31+00:00Added an answer on June 16, 2026 at 5:36 am

    You have to define better what you mean by null chars.

    When you show ' ', those are space chars. There are several intrepetations of the word null. In DB land NULL is special word that means “an unknown value”. In programming NUL, or NULL, or null, probably mean the char \000. That digital value is used as a special marker to indicate in ‘C’ programs (at least) “end-of-string”.

    Assuming that you mean space chars, you can search for them exactly has you have defined them:

    if [ $extracted -eq '       ' ] 
    #--------------------^^^^^^^
    

    But note of course that $exacted cannot equal both 000000 AND ‘ ‘, right?

    It maybe that you’ll find it easier to test for these values like

    if echo "$extract" | grep -q '000000' ; then
          echo found 000000
    fi
    if echo "$extract" | grep -q '      ' ; then
           echo found spaces
    fi
    

    Note, because of the special meaning for \000 to c-lang programs, including grep and about everything in unix, you can’t reliably do

    if echo "$extract" | grep -q '\000\000\000\000\000\000\000' ; then 
     ....
    

    (Actually, that might work, becuase “$extract” is not a file, but if you try grep -q '\000' myFile, that probably won’t work reliably, as by definition a file with a ‘\000’ inside is a binary file, not a text file, and grep, et.al. are tools for scanning text files).

    There are likely tricks to find these if that is really what you want, so please edit your question to indicate if that is your requirement.

    IHTH

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

Sidebar

Related Questions

i am testing with the shell script below: #!/bin/ksh -x instance=`echo $1 | cut
I have the below line in the unix shell script. I want to exclude
I have the below shell script in which sql file is called which has
I am using the below code for replacing a string inside a shell script.
I'm attempting to emulate the functionality of the bash shell script below using a
What is wrong with the following code in shell script : Below code throwing
I have three shell script which I am running as below- sh -x script1.sh
I'm trying to install MySQL on Ubuntu Natty from a shell script. However, I
i have unix shell script which is need to be run like below test_sh
I have below lines in my shell script. #!/bin/bash counter=0 counter=$((counter+1)) echo $counter And

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.