echo -n "which names (lower case only)?"
read name
입력이 다음과 같다고 가정합시다. brmu ankr ista
텍스트 파일 wrt 사용자 입력에서 20 번째 줄 뒤에 특정 줄을 다음과 같이 줄의 시작 부분에서 하나의 공백으로 작성해야합니다.
brmu_gps expt ftprnx
ankr_gps expt ftprnx
ista_gps expt ftprnx
Perl 사용 :
<<<"$x" perl -i -pe 'if($.==21){foreach(split(" ",<STDIN>)){print"${_}_gps expt ftprnx\n"}}' file
확장 된 Perl 스크립트 :
if($. == 21) { # if the current line's number is 21
foreach(split(" ", <STDIN>)) { # splits STDIN on spaces and returns the splitted elements as an array; for each member of the array
print("${_}_gps expt ftprnx\n") # print the current element followed by `_gps expt ftprnx` and a newline character
}
}
<<<"$x"
: 변수에서 입력을 읽습니다 x
.-i
in perl
: "<>"구조로 처리 된 파일이 내부 편집되도록 지정합니다.-p
in perl
: Perl은 프로그램 주위에서 다음과 같은 루프를 가정하여 sed와 비슷한 파일 이름 인수를 반복합니다.
LINE:
while (<>) {
... # your program goes here
} continue {
print or die "-p destination: $!\n";
}
-e
in perl
: 프로그램의 한 줄을 입력하는 데 사용할 수 있습니다.% cat file
line #1
line #2
line #3
line #4
line #5
line #6
line #7
line #8
line #9
line #10
line #11
line #12
line #13
line #14
line #15
line #16
line #17
line #18
line #19
line #20
line #21
line #22
line #23
line #24
line #25
% read x
brmu ankr ista
% <<<"$x" perl -i -pe 'if($.==21){foreach(split(" ",<STDIN>)){print"${_}_gps expt ftprnx\n"}}' file
% cat file
line #1
line #2
line #3
line #4
line #5
line #6
line #7
line #8
line #9
line #10
line #11
line #12
line #13
line #14
line #15
line #16
line #17
line #18
line #19
line #20
brmu_gps expt ftprnx
ankr_gps expt ftprnx
ista_gps expt ftprnx
line #21
line #22
line #23
line #24
line #25
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다