سؤال
سيؤدي العبارة التالية إلى إزالة أرقام السطر في ملف TXT: giveacodicetagpre.
يتم إنشاء ملف الإدخال بالبيان التالي (هذا واحد أفهم): giveacodicetagpre.
أعرف وظيفة القط وأعرف أن الإخراج مكتوب إلى ملف "windlinenumbers.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