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

  • SEARCH
  • Home
  • 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 7020303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:18:04+00:00 2026-05-27T23:18:04+00:00

I have a file with contents: $> cat file 1 2 4 Now, I

  • 0

I have a file with contents:

$> cat file
1
2
4

Now, I would like to use/run another script, if the differences between the numbers (subtraction) is larger than 1, else exit from the main script.

I tried to do this in the following way, but does not work:

less file \
| awk '\
    function abs(x){return (((x < 0.0) ? -x : x) + 0.0)}\
    BEGIN{i=1;}\
    {new=old;old=$1}\
    {if(abs($1-new)>1)i++;}
    END{if(i>1) print 1; else print 0;}' \
| while read i;do
 if (( ${i} ));then
 echo -n "Would you like to continue? [yes or no]: "
 read yno
   case ${yno} in   
       y )
           echo Continuing...
           ;;
       n )
           echo Exiting...
           ;;
       * )
           echo "Invalid input"
           ;;
   esac
 else echo Cont...
 fi
done

I would expect, that if ${i}==1, then I can make a decision, whether I want to continue or not.

  • 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-05-27T23:18:05+00:00Added an answer on May 27, 2026 at 11:18 pm

    you wrote

    I would expect, that if ${i}==1,

    Yes, but what if ${i} = “Error on input” or some other value, your statement needs to explicitly state your condition. Also using less to send a file to a pipe is not a standard situation, why not just pass in the filename to awk for processing, i.e.

    awk '\
        function abs(x){return (((x < 0.0) ? -x : x) + 0.0)}\
        BEGIN{i=1;}\
        {new=old;old=$1}\
        {if(abs($1-new)>1)i++;}
        END{if(i>1) print 1; else print 0;}' file1 \
      | while read i;do
     if (( "${i}" == 1 ));then
     echo -n "Would you like to continue? [yes or no]: "
     read yno
     . . .
    

    I hope this helps

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

Sidebar

Related Questions

I have a file called 'removethese' who's contents looks like this: ./test_dir/file1 ./test_dir/file2 ./test_dir/file
I have a text file, a.txt. Contents are: $ cat a.txt microsoft.com google.com ibm.com
I have a file a.txt . cat a.txt > hello The contents of a.txt
I have a file with contents abc def high lmn ... ... There are
So I have the following .htaccess file contents from my other project which is
I have a file,named f1.txt, whose contents are 75 15 85 35 60 50
I have a file, and I need to send its contents to a function.
I have read that CURL is way too fast than File Get Contents and
I have a file which has contents on every line following this format (A,
I have file contents in a java string variable, which I want to convert

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.