1
Insert multiple lines in a specific position of a file
source link: https://donghao.org/2022/07/01/insert-multiple-lines-in-a-specific-position-of-a-file/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Insert multiple lines in a specific position of a file
I used awk for quite a long time, but not his brother sed. A couple of days ago I want to insert two lines for a CMake file in a specific position and find a perfect answer: here.
Now I could add two lines by using:
sed -i '/^enable_language/i set(CMAKE_CUDA_ARCHITECTURES 86)\nset(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)' \ cmake/public/cuda.cmake
Shell
sed -i '/^enable_language/i set(CMAKE_CUDA_ARCHITECTURES 86)\nset(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)' \
cmake/public/cuda.cmake
The CMake file changed from:
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}") endif() enable_language(CUDA) set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) set(CMAKE_CUDA_STANDARD_REQUIRED ON)
CMake
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}")
endif()
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}") endif() set(CMAKE_CUDA_ARCHITECTURES 86) set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc) enable_language(CUDA) set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) set(CMAKE_CUDA_STANDARD_REQUIRED ON)
CMake
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}")
endif()
set(CMAKE_CUDA_ARCHITECTURES 86)
set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
Related Posts
- About ext4 file system
Recently I make a presentation about my past works on linux kernel. Then I find…
- Finding core-dump file
In a new server, my program got 'core dump'. But I haven't found the core-dump…
- Use matplotlib to draw multiple pictures
To draw some sample images in one page, I used one of the most popular…
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK