0

I'm new to Linux and Bat Scripts so this question might seem easy to many of you.

I have a bat script that is supposed to overwrite a file with text. I'm unable to copy all the text because it includes ">>" within the text i want to copy.

Example:

ECHO "echo -e Text_to_copy >> /home/fileA.csv" >A.txt

The code above works but the quotations (") are copied as well and I need them removed from my end result (A.txt). If I use apostrophes (') instead of quotations then, I only get partial text added to my end file (echo -e Text_to_copy)

Any advice is appreciated

Toto
  • 89,455
  • 62
  • 89
  • 125
  • 1
    If you're on Linux, you should be using a bourne shell variant, and `echo "foo >> bar"` will work just fine without writing the quotes. – William Pursell May 13 '21 at 13:05
  • Im using a BAT script , after writing into the file I need to add the text to a remote server. I'm using PLINK for that. Would "bourne shell variant" work for that as well? – Alon Avisar May 13 '21 at 13:46
  • `sh`, `bash`, `zsh`, `ksh` are typical shells in Linux. Modifying files on a remote host is typically done via `ssh` or `rsync` or `scp`. If you're going to learn Linux, it's probably best to become familiar with the standard toolset. – William Pursell May 13 '21 at 14:25
  • Linux does not support BAT scripts. Please re-tag the question for Windows and cmd.exe if Linux is not involved. – that other guy May 13 '21 at 18:48

2 Answers2

0

Bash works as expeced:

andrew@andrew-Ubuntu:~$ echo "echo -e Text_to_copy >> /home/fileA.csv" >A.txt
andrew@andrew-Ubuntu:~$ cat A.txt 
echo -e Text_to_copy >> /home/fileA.csv
andrew@andrew-Ubuntu:~$ 
Andrew
  • 123
  • 1
  • 7
0

It may fix your Problem

IF YOU WANT TO ADD MORE LINES THEN ADD INTO INFORMATION FIELD

MAKE SURE TO USE DOUBLE-QUOTES (") WHILE ADDING INFORMATION

@echo off 
setlocal enableextensions disabledelayedexpansion
set "textFile=a.txt"

::----------Information--------
echo "echo -e Text_to_copy >> /home/fileA.csv">%textfile%

::-----------------------------

    set se="
    set rl=

    for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
        set "line=%%i"
        setlocal enabledelayedexpansion
        >>"%textFile%" echo(!line:%se%=%rl%!
        endlocal
    )

SOURCE : Batch script to find and replace a string in text file without creating an extra output file for storing the modified file

Stephan
  • 53,940
  • 10
  • 58
  • 91
Biltu Das
  • 21
  • 1
  • 4
  • `"` is called "Double-quotes" (or sometimes just "Quotes"). "Inverted commas" are typographical quotes used in text processing. They just don't work in `cmd` – Stephan Jun 23 '21 at 06:24