문제
다음 명령문은 txt 파일에서 행 번호를 제거합니다.
cat withLineNumbers.txt | sed 's/^.......//' >> withoutLineNumbers.txt
.
입력 파일은 다음 명령문으로 작성됩니다 (이 하나의 이해) :
nl -ba input.txt >> withLineNumbers.txt
.
나는 고양이의 기능을 알고 있고 출력이 'viledlineNumbers.txt'파일에 기록된다는 것을 알고 있습니다.그러나 '| sed 's/^.......//''
의 일부는 나에게 실제로 분명하지 않습니다.
시간에 감사드립니다.
해결책
That sed regular expression simply removes the first 7 characters from each line. The regular expression ^.......
says "Any 7 characters at the beginning of the line." The sed argument s/^.......//
substitutes the above regular expression with an empty string.
Refer to the sed(1)
man page for more information.
다른 팁
that sed statement says the delete the first 7 characters. a dot "." means any character. There is an even easier way to do this
awk '{print $2}' withLineNumbers.txt
you just have to print out the 2nd column using awk. No need to use regex
if your data has spaces,
awk '{$1="";print substr($0,2)}' withLineNumbers.txt
sed is doing a search and replace. The 's' means search, the next character ('/') is the seperator, the search expression is '^.......', and the replace expression is an empty string (i.e. everything between the last two slashes).
The search is a regular expression. The '^' means match start of line. Each '.' means match any character. So the search expression matches the first 7 characters of each line. This is then replaced with an empty string. So what sed is doing is removing the first 7 characters of each line.
A more simple way to achieve the same think could be:
cut -b8- withLineNumbers.txt > withoutLineNumbers.txt