I need to sort a file, the sort is not a alphabetical sort, it's based on a predefined order which is read from a file called fSortOrder.
The format of the fSortOrder file is :
STARTPATH"
....
....
The file that needs to be sorted is called tmpUnsorted and contains data in the format :
<add key="STARTPATH" value="\\njros1a2226\LIFEPRO\V13\START" />
....
....
I read the fSortOrder file one line at a time and place this in a variable called lineMO. I use the line below to search the input for the variable :
isThere="$(grep $lineMO tmpUnsorted)"
This appears to work fine, but messes up the data, instead of placing
<add key="STARTPATH" value="\\njros1a2226\LIFEPRO\V13\START" /> in the variable.
<add key="STARTPATH" value="\njros1a2226\LIFEPRO\V13\START" /> is placed in the varialbe.
Is there anyway to fix this as the double \\ is vital and the file is useless without it.
Using '$lineMO' also does not work because the ' ' negates the meaing of $ and searches for the string $lineMO in the file rather than the contents of the variable $lineMO
The grep command is only going to return what it finds in tmpUnsorted so if there is not a tab in tmpUnsorted I would check your code to see where you have embeded it.
Removing a leading tab(specifally for your code):
TABLESS=$(print -r $isThere | sed 's/=" */="/') # Removes multiple whitspaces after ="
TAB=$(printf "\t")
TABLESS=$(print -r $isThere | sed "s/=\"$TAB/=\"/") # Removes single tab character after ="