다양한 wav 파일의 경로가 포함된 텍스트 파일이 있습니다. 하지만 생성되면 알파벳순으로 정렬됩니다. 그럼 경로는 이렇습니다
/home/wav_path/converted_Interpreter_TC_100.wav
/home/wav_path/converted_Interpreter_TC_101.wav
/home/wav_path/converted_Interpreter_TC_102.wav
/home/wav_path/converted_Interpreter_TC_103.wav
/home/wav_path/converted_Interpreter_TC_104.wav
/home/wav_path/converted_Interpreter_TC_105.wav
/home/wav_path/converted_Interpreter_TC_106.wav
/home/wav_path/converted_Interpreter_TC_107.wav
/home/wav_path/converted_Interpreter_TC_108.wav
/home/wav_path/converted_Interpreter_TC_109.wav
/home/wav_path/converted_Interpreter_TC_10.wav
/home/wav_path/converted_Interpreter_TC_110.wav
/home/wav_path/converted_Interpreter_TC_111.wav
/home/wav_path/converted_Interpreter_TC_11.wav
/home/wav_path/converted_Interpreter_TC_12.wav
/home/wav_path/converted_Interpreter_TC_13.wav
/home/wav_path/converted_Interpreter_TC_14.wav
/home/wav_path/converted_Interpreter_TC_15.wav
/home/wav_path/converted_Interpreter_TC_16.wav
/home/wav_path/converted_Interpreter_TC_17.wav
/home/wav_path/converted_Interpreter_TC_18.wav
/home/wav_path/converted_Interpreter_TC_19.wav
/home/wav_path/converted_Interpreter_TC_1.wav
/home/wav_path/converted_Interpreter_TC_20.wav
/home/wav_path/converted_Interpreter_TC_21.wav
/home/wav_path/converted_Interpreter_TC_22.wav
/home/wav_path/converted_Interpreter_TC_23.wav
/home/wav_path/converted_Interpreter_TC_24.wav
/home/wav_path/converted_Interpreter_TC_25.wav
/home/wav_path/converted_Interpreter_TC_26.wav
/home/wav_path/converted_Interpreter_TC_27.wav
/home/wav_path/converted_Interpreter_TC_28.wav
/home/wav_path/converted_Interpreter_TC_29.wav
/home/wav_path/converted_Interpreter_TC_2.wav
/home/wav_path/converted_Interpreter_TC_30.wav
/home/wav_path/converted_Interpreter_TC_31.wav
/home/wav_path/converted_Interpreter_TC_32.wav
/home/wav_path/converted_Interpreter_TC_33.wav
/home/wav_path/converted_Interpreter_TC_34.wav
/home/wav_path/converted_Interpreter_TC_35.wav
/home/wav_path/converted_Interpreter_TC_36.wav
/home/wav_path/converted_Interpreter_TC_37.wav
/home/wav_path/converted_Interpreter_TC_38.wav
/home/wav_path/converted_Interpreter_TC_39.wav
/home/wav_path/converted_Interpreter_TC_3.wav
/home/wav_path/converted_Interpreter_TC_40.wav
/home/wav_path/converted_Interpreter_TC_41.wav
/home/wav_path/converted_Interpreter_TC_42.wav
/home/wav_path/converted_Interpreter_TC_43.wav
/home/wav_path/converted_Interpreter_TC_44.wav
/home/wav_path/converted_Interpreter_TC_45.wav
/home/wav_path/converted_Interpreter_TC_46.wav
/home/wav_path/converted_Interpreter_TC_47.wav
/home/wav_path/converted_Interpreter_TC_48.wav
/home/wav_path/converted_Interpreter_TC_49.wav
/home/wav_path/converted_Interpreter_TC_4.wav
/home/wav_path/converted_Interpreter_TC_50.wav
/home/wav_path/converted_Interpreter_TC_51.wav
/home/wav_path/converted_Interpreter_TC_52.wav
/home/wav_path/converted_Interpreter_TC_53.wav
/home/wav_path/converted_Interpreter_TC_54.wav
/home/wav_path/converted_Interpreter_TC_55.wav
/home/wav_path/converted_Interpreter_TC_56.wav
/home/wav_path/converted_Interpreter_TC_57.wav
/home/wav_path/converted_Interpreter_TC_58.wav
/home/wav_path/converted_Interpreter_TC_59.wav
/home/wav_path/converted_Interpreter_TC_5.wav
/home/wav_path/converted_Interpreter_TC_60.wav
/home/wav_path/converted_Interpreter_TC_61.wav
/home/wav_path/converted_Interpreter_TC_62.wav
/home/wav_path/converted_Interpreter_TC_63.wav
/home/wav_path/converted_Interpreter_TC_64.wav
/home/wav_path/converted_Interpreter_TC_65.wav
/home/wav_path/converted_Interpreter_TC_66.wav
/home/wav_path/converted_Interpreter_TC_67.wav
/home/wav_path/converted_Interpreter_TC_68.wav
/home/wav_path/converted_Interpreter_TC_69.wav
/home/wav_path/converted_Interpreter_TC_6.wav
/home/wav_path/converted_Interpreter_TC_70.wav
/home/wav_path/converted_Interpreter_TC_71.wav
/home/wav_path/converted_Interpreter_TC_72.wav
/home/wav_path/converted_Interpreter_TC_73.wav
/home/wav_path/converted_Interpreter_TC_74.wav
/home/wav_path/converted_Interpreter_TC_75.wav
/home/wav_path/converted_Interpreter_TC_76.wav
/home/wav_path/converted_Interpreter_TC_77.wav
/home/wav_path/converted_Interpreter_TC_78.wav
/home/wav_path/converted_Interpreter_TC_79.wav
/home/wav_path/converted_Interpreter_TC_7.wav
/home/wav_path/converted_Interpreter_TC_80.wav
/home/wav_path/converted_Interpreter_TC_81.wav
/home/wav_path/converted_Interpreter_TC_82.wav
/home/wav_path/converted_Interpreter_TC_83.wav
/home/wav_path/converted_Interpreter_TC_84.wav
/home/wav_path/converted_Interpreter_TC_85.wav
/home/wav_path/converted_Interpreter_TC_86.wav
/home/wav_path/converted_Interpreter_TC_87.wav
/home/wav_path/converted_Interpreter_TC_88.wav
/home/wav_path/converted_Interpreter_TC_89.wav
/home/wav_path/converted_Interpreter_TC_8.wav
/home/wav_path/converted_Interpreter_TC_90.wav
/home/wav_path/converted_Interpreter_TC_91.wav
/home/wav_path/converted_Interpreter_TC_92.wav
/home/wav_path/converted_Interpreter_TC_93.wav
/home/wav_path/converted_Interpreter_TC_94.wav
/home/wav_path/converted_Interpreter_TC_95.wav
/home/wav_path/converted_Interpreter_TC_98.wav
/home/wav_path/converted_Interpreter_TC_99.wav
/home/wav_path/converted_Interpreter_TC_9.wav
TC 다음의 숫자를 기준으로 정렬하여 다음과 같이 보이도록 하고 싶습니다.
/home/wav_path/converted_Interpreter_TC_1.wav
/home/wav_path/converted_Interpreter_TC_2.wav
/home/wav_path/converted_Interpreter_TC_3.wav
/home/wav_path/converted_Interpreter_TC_4.wav
sort
나는 사용해 보았지만 sort -n
그 중 아무것도 작동하지 않았습니다. 누구든지 이 문제를 해결하도록 도와줄 수 있나요?
답변1
파일 이름이 표시된 것과 정확히 일치하는 경우 다음으로 정의된 다섯 번째 필드에서 숫자로 정렬하려고 합니다 _
.
/home/wav_path/converted_Interpreter_TC_1.wav
_________ ______________ ___________ __ _____
1st field 2nd field 3d field 4th 5th
따라서 다음과 같이 할 수 있습니다.
$ sort -t _ -nk5,5 names
/home/wav_path/converted_Interpreter_TC_1.wav
/home/wav_path/converted_Interpreter_TC_2.wav
/home/wav_path/converted_Interpreter_TC_3.wav
/home/wav_path/converted_Interpreter_TC_4.wav
/home/wav_path/converted_Interpreter_TC_5.wav
/home/wav_path/converted_Interpreter_TC_6.wav
/home/wav_path/converted_Interpreter_TC_7.wav
/home/wav_path/converted_Interpreter_TC_8.wav
/home/wav_path/converted_Interpreter_TC_9.wav
/home/wav_path/converted_Interpreter_TC_10.wav
/home/wav_path/converted_Interpreter_TC_11.wav
/home/wav_path/converted_Interpreter_TC_12.wav
/home/wav_path/converted_Interpreter_TC_13.wav
/home/wav_path/converted_Interpreter_TC_14.wav
/home/wav_path/converted_Interpreter_TC_15.wav
/home/wav_path/converted_Interpreter_TC_16.wav
/home/wav_path/converted_Interpreter_TC_17.wav
/home/wav_path/converted_Interpreter_TC_18.wav
/home/wav_path/converted_Interpreter_TC_19.wav
/home/wav_path/converted_Interpreter_TC_20.wav
/home/wav_path/converted_Interpreter_TC_21.wav
/home/wav_path/converted_Interpreter_TC_22.wav
/home/wav_path/converted_Interpreter_TC_23.wav
/home/wav_path/converted_Interpreter_TC_24.wav
/home/wav_path/converted_Interpreter_TC_25.wav
/home/wav_path/converted_Interpreter_TC_26.wav
/home/wav_path/converted_Interpreter_TC_27.wav
/home/wav_path/converted_Interpreter_TC_28.wav
/home/wav_path/converted_Interpreter_TC_29.wav
/home/wav_path/converted_Interpreter_TC_30.wav
/home/wav_path/converted_Interpreter_TC_31.wav
/home/wav_path/converted_Interpreter_TC_32.wav
/home/wav_path/converted_Interpreter_TC_33.wav
/home/wav_path/converted_Interpreter_TC_34.wav
/home/wav_path/converted_Interpreter_TC_35.wav
/home/wav_path/converted_Interpreter_TC_36.wav
/home/wav_path/converted_Interpreter_TC_37.wav
/home/wav_path/converted_Interpreter_TC_38.wav
/home/wav_path/converted_Interpreter_TC_39.wav
/home/wav_path/converted_Interpreter_TC_40.wav
/home/wav_path/converted_Interpreter_TC_41.wav
/home/wav_path/converted_Interpreter_TC_42.wav
/home/wav_path/converted_Interpreter_TC_43.wav
/home/wav_path/converted_Interpreter_TC_44.wav
/home/wav_path/converted_Interpreter_TC_45.wav
/home/wav_path/converted_Interpreter_TC_46.wav
/home/wav_path/converted_Interpreter_TC_47.wav
/home/wav_path/converted_Interpreter_TC_48.wav
/home/wav_path/converted_Interpreter_TC_49.wav
/home/wav_path/converted_Interpreter_TC_50.wav
/home/wav_path/converted_Interpreter_TC_51.wav
/home/wav_path/converted_Interpreter_TC_52.wav
/home/wav_path/converted_Interpreter_TC_53.wav
/home/wav_path/converted_Interpreter_TC_54.wav
/home/wav_path/converted_Interpreter_TC_55.wav
/home/wav_path/converted_Interpreter_TC_56.wav
/home/wav_path/converted_Interpreter_TC_57.wav
/home/wav_path/converted_Interpreter_TC_58.wav
/home/wav_path/converted_Interpreter_TC_59.wav
/home/wav_path/converted_Interpreter_TC_60.wav
/home/wav_path/converted_Interpreter_TC_61.wav
/home/wav_path/converted_Interpreter_TC_62.wav
/home/wav_path/converted_Interpreter_TC_63.wav
/home/wav_path/converted_Interpreter_TC_64.wav
/home/wav_path/converted_Interpreter_TC_65.wav
/home/wav_path/converted_Interpreter_TC_66.wav
/home/wav_path/converted_Interpreter_TC_67.wav
/home/wav_path/converted_Interpreter_TC_68.wav
/home/wav_path/converted_Interpreter_TC_69.wav
/home/wav_path/converted_Interpreter_TC_70.wav
/home/wav_path/converted_Interpreter_TC_71.wav
/home/wav_path/converted_Interpreter_TC_72.wav
/home/wav_path/converted_Interpreter_TC_73.wav
/home/wav_path/converted_Interpreter_TC_74.wav
/home/wav_path/converted_Interpreter_TC_75.wav
/home/wav_path/converted_Interpreter_TC_76.wav
/home/wav_path/converted_Interpreter_TC_77.wav
/home/wav_path/converted_Interpreter_TC_78.wav
/home/wav_path/converted_Interpreter_TC_79.wav
/home/wav_path/converted_Interpreter_TC_80.wav
/home/wav_path/converted_Interpreter_TC_81.wav
/home/wav_path/converted_Interpreter_TC_82.wav
/home/wav_path/converted_Interpreter_TC_83.wav
/home/wav_path/converted_Interpreter_TC_84.wav
/home/wav_path/converted_Interpreter_TC_85.wav
/home/wav_path/converted_Interpreter_TC_86.wav
/home/wav_path/converted_Interpreter_TC_87.wav
/home/wav_path/converted_Interpreter_TC_88.wav
/home/wav_path/converted_Interpreter_TC_89.wav
/home/wav_path/converted_Interpreter_TC_90.wav
/home/wav_path/converted_Interpreter_TC_91.wav
/home/wav_path/converted_Interpreter_TC_92.wav
/home/wav_path/converted_Interpreter_TC_93.wav
/home/wav_path/converted_Interpreter_TC_94.wav
/home/wav_path/converted_Interpreter_TC_95.wav
/home/wav_path/converted_Interpreter_TC_98.wav
/home/wav_path/converted_Interpreter_TC_99.wav
/home/wav_path/converted_Interpreter_TC_100.wav
/home/wav_path/converted_Interpreter_TC_101.wav
/home/wav_path/converted_Interpreter_TC_102.wav
/home/wav_path/converted_Interpreter_TC_103.wav
/home/wav_path/converted_Interpreter_TC_104.wav
/home/wav_path/converted_Interpreter_TC_105.wav
/home/wav_path/converted_Interpreter_TC_106.wav
/home/wav_path/converted_Interpreter_TC_107.wav
/home/wav_path/converted_Interpreter_TC_108.wav
/home/wav_path/converted_Interpreter_TC_109.wav
/home/wav_path/converted_Interpreter_TC_110.wav
/home/wav_path/converted_Interpreter_TC_111.wav
이는 필드 구분 기호 sort
로 사용되며 5번째 필드( )만 숫자로 정렬( )함을 나타냅니다._
-n
-k5,5
또는 GNU가 있는 경우 다음을 sort
사용하십시오 -V
.
-V, --version-sort
natural sort of (version) numbers within text
그래서 당신은 할 수 있습니다
sort -V names
동일한 결과를 얻습니다.
답변2
"파일 이름 속성별로 정렬하고 싶습니다"의 프로세스는 다음과 같습니다.
- 장식(예: 정렬에 사용되는 키를 앞에 배치)
- 유형
- 장식하다
만약에, 그리고오직이러한 특정 파일 이름에 개행 문자가 포함될 수 없다는 것을 알고 있는 경우 숫자를 정규식과 일치시키고 줄 시작 부분에서 반복한 다음 숫자별로 정렬하여 파일 이름을 장식할 수 있습니다.
이 경우 체인은 다음과 같습니다.
<your_text_file \
sed -n 's;^your_beginning_pattern\([[:digit:]]*\)your_end_pattern$;\1 &;p' | \
sort -n | \
sed 's;^[[:digit:]]* \(.*\)$;\1;'
your_
모든 것을 사용 사례에 적용되는 것으로 바꿔야 합니다 . (이것은 귀하의 작은 예에서 완벽하게 실행 가능해야 합니다. 한번 시도해 보세요!)
(이렇게 하면 sed -n … ;p'
패턴과 일치하는 행만 인쇄됩니다. 따라서 실수로 패턴과 일치하지 않는 파일을 포함하면 해당 파일은 제외됩니다. 이를 원하지 않으면 -n
sed 옵션과 p
플래그를 사용하지 마십시오.