1

I have a log.txt file which contains 20k lines. Each line having numbers and there xyz plane coordinates and they are separated by sets. Sets can be identify by there names as ABC_1, ABC_2 and so on in the log.txt

From this log.txt file I want to segregate all sets data in to individual Text files, which should contain all data from set (eg. ABC_1).

My log.txt looks like below.

ABC_1: 
1, (xyz coordinates)
2, (xyz coordinates)
3, (xyz coordinates)

 .... Continue
ABC_2: 
101, (xyz coordinates)
102, (xyz coordinates)
103, (xyz coordinates)

 .... Continue
ABC_3: 
201, (xyz coordinates)
202, (xyz coordinates)
203, (xyz coordinates)

.... Continue
ABC_99: 
9991, (xyz coordinates)
9992, (xyz coordinates)
9993, (xyz coordinates)

.... Continue

I want to create a script which can give me 99 individual text files from a single log.txt file and which should be named as set name ABC_1.TXT, ABC_2.TXT ... to ABC_99.TXT from log.txt.

αғsнιη
  • 41,407
Aniket
  • 11

2 Answers2

2

With csplit

csplit -s -b %d.txt -f ABC_ Log.txt /ABC_/ {*}
ctac_
  • 1,960
1

Awk solution:

awk '/^ABC_/{
         if (fn) close(fn); sub(":", "", $1);
         fn = $1".txt"; next
    }
    { print > fn }' Log.txt