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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:39:56+00:00 2026-06-14T19:39:56+00:00

I have searched high and low, but cannot seem to find a solution to

  • 0

I have searched high and low, but cannot seem to find a solution to this problem (maybe it doesn’t exist?). Here is my problem:

I have a file on my local machine called myFile.txt. There is a file on a remote machine with the same name (myFile.txt). Both file structures look like this:

<tag1>November 22, 2012<tag1>
<tag2>version5.8<tag2>
<tag3>ASDFA23RASDF29ASDJ29DJ2<tag3>

Both files have this exact same layout. I need to write a script keeps the string in between <tag3> in sync for the two files (local and remote). I need to get the string from <tag3> on the remote server and compare it to the same string on my local machine. If there is a difference I need to change my local string to reflect the remote one.

What I’ve tried thus far:
I’ve grabbed the local string using awk, and assigned it to a variable. Easy enough. I ssh’ed into the remote server and attempted to use the same method to assign the remote string to a variable. As far as I can tell, this seems to be working. The issue is the variable doesn’t come back to my local machine with a value (if that makes sense). This is how I’m attempting to do this:

#!/bin/bash

fileName="myFile.txt"
logon="myUserName@remoteServer.com"


localString=$(awk -F "<tag3>" '{print $2}' $fileName)

x=$(ssh $logon "remoteString=$(awk -F "<tag3>" '{print $2}' $fileName); echo $remoteString")
echo "remote string = $x" 

if [ $localString == $x ]; then
echo "The 2 auth keys are EQUAL!!!"
else
echo "The 2 auth keys are NOT equal!!!"
fi  

I can see the variable being assigned when I echo out $remoteString. From my understanding this is happening on the remote server though as I’m getting the correct string printed to console followed by “command not found”. The next line echo’s “remote string = “. So $x is either losing it’s value or is never properly assigned. I’ve tried varying this line where $x is assigned many many time, but have not had any luck.

Other ideas:
If this isn’t possible I’m beginning to think maybe I need to do a scp of the file, bring it over to my server, make the comparison, and then delete the copied filed. I would need to change the name of the copy before moving it to my local machine, or else I will overwrite my file. Also, it would seem more efficient not to have to make a secure copy because this script will have to run on many machines, and the file will potentially be a lot bigger than 3 lines. I’ve looked into diff, but can’t find a way to get it to compare just one line.

I am fairly new to bash scripting so please forgive me if I am missing something obvious. Thank you for any help as it is greatly appreciated.

  • 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-14T19:39:58+00:00Added an answer on June 14, 2026 at 7:39 pm

    You can use something along these lines:

    #!/bin/bash 
    fileName="myFile.txt"
    logon="myUserName@remoteServer.com"
    
    sedcommand='/^<tag3>.*<tag3>$/{s/<tag3>\(.*\)<tag3>/\1/p;q}'
    
    localString=$( sed -n $sedcommand "$fileName" )
    remoteString=$( ssh "$logon" "sed -n '$sedcommand' \"$fileName\"" )
    
    if [[ $localString == $remoteString ]]; then
        echo "The 2 auth keys are EQUAL!!!"
    else
        echo "The 2 auth keys are NOT equal!!!"
    fi
    

    (which seems simpler than your method). The sed command finds the first occurence of a line starting by <tag3> and ending by <tag3> and removes the tags so as to transfer only the “auth key”. There’s no guard against files that don’t exist, or against the tag not being find. This detail is left to the reader. But the script is safe regarding spaces in file names and doesn’t use two nested subshells!

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

Sidebar

Related Questions

I have searched high and low for a solution but I dont seem to
I have searched high and low for documentation on this, but I just cannot
I have searched for a general solution to this but only find answers to
I have searched high and low, but I can't figure this one out. I
I've searched high and low, but I could not find a solution, to what
I have searched high and low but can't get this to work. TextView topic
I have searched high and low and cannot find a Samsung Omnia SDK. I
I have searched high and low for this problem... and I found a lot
I have searched high, low, far and wide but can not find anything on
I have searched high and low for this solution. Any insights will be highly

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.