bash script vs command line

Posted on 2004-11-22
Last Modified: 2010-04-17
Greetings Experts,

I am able to run the following from command line:
grep "1234 ABC\1.0" file.txt | grep ABCDEFGH01 | grep ALPHAONE | wc -l

When I attempt to do the same in a bash script, I don't get the same result.

How do I correct this?

Question by:uluttrell

    Expert Comment

    If your bash-script is looking like this:

    grep "1234 ABC\1.0" file.txt | grep ABCDEFGH01 | grep ALPHAONE | wc -l

    you should get the same result.. how does the results differ?

    Author Comment

    If i run the grep command the prompt i get the total number of occurrences.  If i run the grep command from within a script I get 0 as the result.
    LVL 1

    Expert Comment

    This '\1.0' equation looks strange to me...
    Try to run: "grep ABCDEFGH01 file.txt | grep ALPHAONE | wc -l" both in command line and in script, and check the results.
    If it works, the problem lies within the first equation.

    Author Comment

    Found the problem.  I had grep -c in the script that interfered with the wc -l.

    Accepted Solution

    PAQed with points refunded (150)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    Help with my python script 6 135
    factorial example challenge 10 44
    word0 challenge 3 26
    python sqlite question 11 17
    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now