My input file looks like this

abc def \
ghi jkl && mno || hju

My objective:
to replace '\' with line 2

newLine=`sed -n "2 p" inputFile`
sed -n 's/\\/'"$newLine"'/p' inputFile | tee inputFile

When i do this, the output i get is ->

abc def abc def ghi jkl \\ mno || hju
but the output should have been
abc def abc def ghi jkl && mno || hju

Why is it that '&&' gets replaced by '\\' ?
Where could i be going wrong ?

Its due to the behaviour of " && "
try this::
line=`sed -n 's/&/x/gp' inputfile`
sed -n 's/\\/'"$line"'/p' inputfile|sed 's/x/\&/g'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.