paste multiple lines string to CMD or Bash variables

18
2014-04
  • Mateusz

    I want to copy multiple lines (splitted by Enter key) from, for example, notepad and then paste it into new variable in CMD or Bash console and after that do some operations on it.

    Although it's quite easy in PowerShell (I simply type

    variable_name="

    then paste copied lines and simply add

    "

    at the end) in predecessor it's much more complicated since CMD interpret each enter as "execute". Is there any other way to accomplish it, instead of save as external text file?

  • Answers
  • invert

    Postfix each line with a \ to indicate multiple lines. Answered on Stack Overflow (although it probably doesn't even belong there.)


  • Related Question

    How can I extract sub-strings using windows command-line?
  • David

    For example say I have a file called testfile.txt that contains a list of file names of the following format:

    A       svn\New Text Document.txt
    M       svn\Table_tblVersion.xml
    

    Is there a command that I can pipe testfile.txt into such that the first 8 characters of each line is removed. The output I want is simply:

    svn\New Text Document.txt
    svn\Table_tblVersion.txt
    

  • Related Answers
  • Siim K

    I really recommend Powershell for such tasks. It's integrated with Windows 7 and you can download it for older versions of Windows.

    The command is:

    get-content testfile.txt | ForEach-Object {$_.Substring(8)} | write-host
    
  • treehead

    You need to run the for command against the file contents:

    for /f "tokens=1*" %a in (testfile.txt) do echo %b
    

    It's nowhere near as versatile as cut in GnuWin coreutils, but it works.

  • RedGrittyBrick

    Step 1. Install Cygwin, UnxUtils or GnuWin32

    Step 2. cut -c9-99 testfile.txt

    If you must use a pipe: cat testfile.txt | cut -c9-99