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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:48:06+00:00 2026-06-08T03:48:06+00:00

Problem: Comparison of files from Pre-check status and Post-check status of a node for

  • 0

Problem: Comparison of files from Pre-check status and Post-check status of a node for specific parameters.

With some help from community, I have written the following solution which extracts the information from files from directories pre and post and based on the “Node-ID” (which happens to be unique and is to be extracted from the files as well). After extracting the data from Pre/post folder, I have created folders based on the node-id and dumped files into the folders.

My Code to extract data (The data is extracted from Pre and Post folders)

FILES=$(find postcheck_logs -type f -name *.log)
for f in $FILES
do
    NODE=`cat $f | grep -m 1 ">" | awk '{print $1}' | sed 's/[>]//g'`  ##Generate the node-id
    echo "Extracting Post check information for " $NODE 
    mkdir temp/$NODE-post  ## create a temp directory
    cat $f | awk 'BEGIN { RS=$NODE"> "; } /^param1/ { foo=RS $0; } END { print foo ; }' > temp/$NODE-post/param1.txt ## extract data
    cat $f | awk 'BEGIN { RS=$NODE"> "; } /^param2/ { foo=RS $0; } END { print foo ; }' > temp/$NODE-post/param2.txt
    cat $f | awk 'BEGIN { RS=$NODE"> "; } /^param3/ { foo=RS $0; } END { print foo ; }' > temp/$NODE-post/param3.txt
done

After this I have a structure as:

/Node1-pre/param1.txt
/Node1-post/param1.txt

and so on.

Now I am stuck to compare $NODE-pre and $NODE-post files,

I have tried to do it using recursive grep, but I am not finding a suitable way to do so. What is the best possible way to compare these files using diff?

Moreover, I find the above data extraction program very slow. I believe it’s not the best possible way (using least resources) to do so. Any suggestions?

  • 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-08T03:48:07+00:00Added an answer on June 8, 2026 at 3:48 am

    Look askance at any instance of cat one-file — you could use I/O redirection on the next command in the pipeline instead.

    You can do the whole thing more simply with:

    for f in $(find postcheck_logs -type f -name *.log)
    do
        NODE=$(sed '/>/{ s/ .*//; s/>//g; p; q; }' $f)  ##Generate the node-id
        echo "Extracting Post check information for $NODE" 
        mkdir temp/$NODE-post
        awk -v NODE="$NODE" -v DIR="temp/$NODE-post" \
            'BEGIN { RS=NODE"> " }
             /^param1/ { param1 = $0 }
             /^param2/ { param2 = $0 }
             /^param3/ { param3 = $0 }
             END {
                 print RS param1 > DIR "/param1.txt"
                 print RS param2 > DIR "/param2.txt"
                 print RS param3 > DIR "/param3.txt"
                 }' $f
    done
    

    The NODE finding process is much better done by a single sed command than cat | grep | awk | sed, and you should plan to use $(...) rather than back-quotes everywhere.

    The main processing of the log file should be done once; a single awk command is sufficient. The script is passed to variables — NODE and the directory name. The BEGIN is cleaned up; the $ before NODE was probably not what you intended. The main actions are very similar; each looks for the relevant parameter name and saves it in an appropriate variable. At the end, it write the saved values to the relevant files, decorated with the value of RS. Semicolons are only needed when there’s more than one statement on a line; there’s just one statement per line in this expanded script. It looks bigger than the original, but that’s only because I’m using vertical space.


    As to comparing the before and after files, you can do it in many ways, depending on what you want to know. If you’ve got a POSIX-compliant diff (you probably do), you can use:

    diff -r temp/$NODE-pre temp/$NODE-post
    

    to report on the differences, if any, between the contents of the two directories. Alternatively, you can do it manually:

    for file in param1.txt param2.txt param3.txt
    do
        if cmp -s temp/$NODE-pre/$file temp/$NODE-post/$file
        then : No difference
        else diff temp/$NODE-pre/$file temp/$NODE-post/$file
        fi
    done
    

    Clearly, you can wrap that in a ‘for each node’ loop. And, if you are going to need to do that, then you probably do want to capture the output of the find command in a variable (as in the original code) so that you do not have to repeat that operation.

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

Sidebar

Related Questions

I have some problems adding my shader-glsl files from one xcode project to another.
I have a performance problem related to string comparison (in Java). I'm working on
I'm having this problem when I tried to extract information from excel files. Here's
I have some problem with sequence generator. I have a file where each line
I have stumbled on a problem that I hope you could help me understand.
Problem: I have a table that prints out vertical but I would like it
Problem: I'm streaming my video from a php file with stream_get_contents(); using Flowplayer as
Problem: I have two array where one produce a category and the second produce
Problem Using Director 11.5 and Windows 7, with MouseWheel Xtra (wheelmouse.zip), I have the
I've got some problem with my function and don't know how to solve this

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.