Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Doubt in cmd comands.  (Read 3442 times)

0 Members and 1 Guest are viewing this topic.

roohi

    Topic Starter


    Beginner

    Doubt in cmd comands.
    « on: June 10, 2009, 12:21:27 AM »
    Hello every one :)

    I have facing a problem while echo a list on command promt , and need the help .

    I have a list:   LIST=abc:::123:::xyz
    Now i want to print this list in a file as follows:
    abc
    123
    xyz

    Now i dont know how to do it , plz help me to slove this.

    Thanks in advance.

    devcom



      Apprentice

      Thanked: 37
      Re: Doubt in cmd comands.
      « Reply #1 on: June 10, 2009, 05:25:58 AM »
      Code: [Select]
      REM SET LIST
      set LIST=abc:::123:::xyz
      REM CHANGE ::: TO "SPACE"
      set LIST=%LIST::::= %

      REM GET ALL TOKENS ON LIST
      for %%a in (%LIST%) do echo %%a

      pause
      Download: Choice.exe

      billrich

      • Guest
      Re: Doubt in cmd comands.
      « Reply #2 on: June 10, 2009, 05:43:40 AM »
      C:\>type finalstr.bat
      Code: [Select]
      @echo off
      set str=abc:::123:::xyz
      echo."%str%"
      set str=%str::= %
      echo %str%

      for /f "tokens=1,2,3,4 delims= " %%a in ("%str%") do ( set x=%%a & set y=%%b & s
      et z=%%c)

      echo.x:  %x%
      echo.y:  %y%
      echo.z:  %z%



      echo  %x%  > savestr.txt
      echo  %y%  >> savestr.txt
      echo  %z%  >> savestr.txt

      echo. The file with each string on separate line

      Type savestr.txt

      Output of finalstr.bat

      C:\>finalstr.bat
      Quote
      "abc:::123:::xyz"
      abc   123   xyz
      x:  abc
      y:  123
      z:  xyz
       The file with each string on separate line
      abc
      123
      xyz
      C:\>

      roohi

        Topic Starter


        Beginner

        Re: Doubt in cmd comands.
        « Reply #3 on: June 12, 2009, 01:24:43 AM »
        thanks, it helps me :)

        gh0std0g74



          Apprentice

          Thanked: 37
          Re: Doubt in cmd comands.
          « Reply #4 on: June 12, 2009, 01:35:40 AM »
          if you have gawk for windows(see my sig )
          Code: [Select]
          C:\test>set str=abc:::123:::xyz

          C:\test>echo %str%|gawk -F":::" "$1=$1" OFS="\n"
          abc
          123
          xyz

          redirect to new file as needed.