finding the strings beween 2 characters "/" & "/" in .txt file

Hi all.
I have a .txt file that I need to sort it
My file is like:

1- 88     chain0  MASTER  (FF-TE)  FFFF  1962510  /TCK          T    FD2TQHVTT1   /jtagc/jtag_instreg/updateinstr_reg_1                                                                              dff1    (TI,SO)         
2-  168    chain0  MASTER  (FF-TE)  FFFF  1961590  /TCK          T    FD1TQNHVTT1  /io_toplevel/pti/bsr_top_inst/bc_pad_cell_PAD_80/u_bc2_obe        
3-  293    chain0  MASTER  (FF-TE)  FFFF  1948940  /TCK          T    FD2TQHVTT1   /external_tdrs/comp_cell_read_shift_reg/data_tdo_reg                                                               dff1    (TI,SO)  
4-...

What I need is to first find the string between 2nd and 3rd "/" that here means
in line 1:jtagc , 2:io_toplevel 3:external_tdrs and then make another .txt file with that name(the one that is found) and put all the same cases in that file and remove from main list
So at the end create for example 3files :
1-jtagc.txt
2-io_toplevel
3-external_tdrs
(Text file is more than 50K lines, so the code should be capable to search line by line)
Thanks in advance :slight_smile:
And sorry for my long question :stuck_out_tongue:

What about:

awk -F/ '{print $3}' infile

or do you mean to sort it:

sort -t/ -k3,3 infile
1 Like

Let me expand Scrutinizer's suggestion:

awk -F/ '{print $3>$3".txt"; $3="";print}' OFS="/" file
1 Like

Or maybe:

awk -F/ '{print $3 > $3 ".txt"}' infile
1 Like

Thanks for your answers
Tnx to Rudic and Frankling52 your codes both works
BUT
the only thing that is misses (I think due to my bad description) is that I need all the line in new file, I mean for example when I have
405 chain0 MASTER (FF-TE) FFFF 1962349 /TCK T FD2TQHVTT1 /jtagc/jtag_censorreg/jtag_test_ctrl_reg_36 dff1 (TI,SO)

and I find "jtagc" I want first remove this line from source file and second I need to move all this line to "jtagc.txt" (And for sure the same for other jtagc iterations)
Thanks

OK, so you want all lines that contain "jtagc" in the file "jtagc.txt" and so on, no lines retained in the original file. Then try

awk -F/ '{print >>$3".txt"}' OFS="/" file

You may need to close($3".txt") the output files if they exceed the number of allowed concurrently open files.

1 Like

You don't need to use >> here > will do the purpose...:slight_smile:

1 Like

Thankss RudiC!!! Helped me a lot :slight_smile:
It did work
Can I ask another question?
script code created something like 100 files
to create a list of all files what should I do?
the exact thing that I need is to create another .txt file that contains the string between 2nd and 3rd "/" and the number of iteration
for example :
1-jtagc 10
2-external_tdrs 15
and so on

Thanks again for your help :slight_smile:

try

awk -F/ '{print >>$3".txt";x[$3]++}END{for(i in x){print i" "x > "all_files.txt"}}' OFS="/" file
1 Like

Pamu and RudiC you both have done a big favour to me :slight_smile:
THANKSS

Well, try

awk -F/ '{print >>$3".txt"; ++cnt[$3]}
          END {for(fn in cnt) printf "%3d %s.txt\n", cnt[fn], fn}
        ' OFS="/" file > fname_distrib.txt
cat fname_distrib.txt
  1 jtagc.txt
  1 external_tdrs.txt
  1 io_toplevel.txt
1 Like