Writing tabs to a file using PowerShell

102

Solution 1

You can use `t for a tab character in a double quoted string. You can also simplify the above to:

"$($fields[0])   $($fields[1])   $($fields[2]) $($fields[3])  $($fields[15])  $($fields[17])" | Add-Content $tempInputDir\testoutput.log

Solution 2

To join the nominated fields together with tabs:

[string]::join("`t", (0..3,15,17 | % {$fields[$_]}))
Share:
102
Abhineet Pandey
Author by

Abhineet Pandey

Updated on April 16, 2020

Comments

  • Abhineet Pandey
    Abhineet Pandey about 4 years

    TLDR: I have two projects(Project A & B) using CMakeLists.txt, both build executables and they work separately. Now, I want to use Project A as a library in Project B, let's call this Project AB. How do I do it?

    Current Directory Structures :

    Project A

    rootA
     |- bin
     |   |-
     |- build
     |   |-
     |- external-includes
     |- CMakeLists.txt with add_subdirectory(libraryA)
     |- libraryA
         |- main.cpp (uses library_A in an example program)
         |- library_A.cpp
         |- library_A.h
         |- Other .h and .cpp files library_A uses
         |- CMakeLists.txt having add_executable (library_A main.cpp library_A.cpp ....)
    

    Project B

    rootB
     |- bin
     |   |-
     |- build
     |   |-
     |- external-includes
     |- CMakeLists.txt with add_subdirectory(libraryB)
     |- libraryB
         |- main.cpp
         |- library_B.cpp
         |- library_B.h
         |- Other .h and .cpp files library_B uses
         |- CMakeLists.txt having add_executable (library_B main.cpp library_B.cpp ....)
    

    Project AB

    rootAB
     |- bin
     |   |-
     |- build
     |   |-
     |- external-includes
     |- rootA 
     |- CMakeLists.txt with add_subdirectory(libraryB)
     |- libraryB
         |- main.cpp
         |- library_B.cpp
         |- library_B.h
         |- Other .h and .cpp files library_B uses
         |- CMakeLists.txt having add_executable (library_B main.cpp library_B.cpp .....)
    

    What I've tried so far:

    I've tried adding include_directories(rootA/libraryA) and add_sudirectory(rootA) to rootAB/CMakeLists.txt and #include <library_A.h> to rootAB/libraryB/main.cpp, then it complains about linking errors(unresolved external symbol). If I add #include <library_A.cpp> , it will complain about other linking errors from library A, which don't occur if I build library_A separately. Probably what I want to do is to build library_A as a (static) library and link it in ProjectAB (preferably using current directory structure and modifications to CMakeLists.txt(s)). How to do so?

    • Some programmer dude
      Some programmer dude about 3 years
      Perhaps you should have the ` add_library` command in the library sub-directories CMakeLists.txt file? Then you can use that library in a target_link_libraries command.
    • Abhineet Pandey
      Abhineet Pandey about 3 years
      @Someprogrammerdude Found this , will try and update the question
  • Chris Magnuson
    Chris Magnuson almost 13 years
    That is a beautiful one liner. Just makes me smile.
  • Wouter
    Wouter over 11 years
    while you're at it: [string]::join("`t", (0..3,15,17 | % {$fields[$_]}))
  • Zarepheth
    Zarepheth over 10 years
    The `t escape sequence is what I was looking for. Note: that is the reversed apostrophe.
  • Peter Mortensen
    Peter Mortensen almost 9 years
    Reversed apostrophe? It is ASCII 96 (0x60). It goes under the names backtick, backquote, and grave accent.