There is a file containing lines:

фильмы|разный текст|еще какойто текст|какие то цифры фильмы|разный текст|еще какойто текст|какие то цифры фильмы|разный текст|еще какойто текст|какие то цифры музыка и клипы|разный текст|еще какойто текст|какие то цифры музыка и клипы|разный текст|еще какойто текст|какие то цифры музыка и клипы|разный текст|еще какойто текст|какие то цифры книги, журналы|разный текст|еще какойто текст|какие то цифры книги, журналы|разный текст|еще какойто текст|какие то цифры книги, журналы|разный текст|еще какойто текст|какие то цифры и тд. 

you need to take all the lines containing "movies" in the first column and save to the file "movies.txt", then take all the lines containing "music and clips" in the first column and save to the file "music and clips.txt", then take all the lines containing " books, magazines "in the first column and save to the file" books, magazines.txt "and so on. with all the hundreds of thousands of lines

strings falling under the same category may go out of order

  • Is your option not suitable? - Vladimir Gamalyan
  • In principle, you need to make console commands? Python / R / any scripting language not suitable? - Ogurtsov
  • @ Human Internet, but in general it is customary to ask questions, and not distribute tasks to free freelancers. Please do not violate any further rules adopted on this site. - aleksandr barakin

1 answer 1

like that:

 $ cut -d '|' -f 1 файл | sort -u | while read p; do grep "^$p[[:space:]]*|" файл > "$p.txt"; done 
  • cut -d '|' -f 1 файл cut -d '|' -f 1 файл - extract the first field from файла lines
  • sort -u - sort the list and remove duplicates
  • while read p; do ...; done while read p; do ...; done - execute a set of instructions for each of the lines (the contents of the line are in the $p variable)
  • grep "^$p[[:space:]]*|" файл grep "^$p[[:space:]]*|" файл - select from the файла lines that start with the search line
  • > "$p.txt - and write them to a file with the specified name.