
변수를 추가하고 싶습니다.끝~의특정한파일의 줄 file.txt
. 지금까지 내 코드는 다음과 같습니다.
#!/bin/bash
read -p "What is the path of the repo? > " input
echo :$input >> file.txt
에 추가하고 싶어요끝~의2호선. 예를 들어,
file.txt
--------
before -
1.stuff
2./home/retep/awesome
after -
1.stuff
2./home/retep/awesome:/home/retep/cool
답변1
awk에 대한 또 다른 단일 라이너입니다.
#!/bin/bash
read -p "What is the path of the repo? > " input
awk -v addition="$input" -v targetline=2 '
NR==targetline { print $0 ":" addition; next}
{print }' file.txt > file.tmp
mv file.tmp file.txt