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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding the strings beween 2 characters "/" & "/" in .txt file
# 1  
Old 10-25-2012
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:
Code:
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 Smilie
And sorry for my long question Smilie


Last edited by Scrutinizer; 10-25-2012 at 08:27 AM.. Reason: code tags
# 2  
Old 10-25-2012
What about:
Code:
awk -F/ '{print $3}' infile

or do you mean to sort it:
Code:
sort -t/ -k3,3 infile

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 10-25-2012
Let me expand Scrutinizer's suggestion:
Code:
awk -F/ '{print $3>$3".txt"; $3="";print}' OFS="/" file

This User Gave Thanks to RudiC For This Post:
# 4  
Old 10-25-2012
Or maybe:
Code:
awk -F/ '{print $3 > $3 ".txt"}' infile

This User Gave Thanks to Franklin52 For This Post:
# 5  
Old 10-25-2012
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
# 6  
Old 10-25-2012
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
Code:
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.
This User Gave Thanks to RudiC For This Post:
# 7  
Old 10-25-2012
Quote:
Originally Posted by RudiC
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
Code:
awk -F/ '{print >>$3".txt"}' OFS="/" file


You don't need to use >> here > will do the purpose...Smilie
This User Gave Thanks to pamu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Web Development

How would I mod_rewrite "/~a1Pha" and "/=a1Pha" to "/paste/a1Pha.htm"? (internally & externally)

Basically I want to shorten URLs on my html pasting site (pasteht.ml), by using "/~a1Pha" instead of "/paste/a1Pha". The ID is 5 numbers and letters, both cases. For example: /~idnum serves /paste/idnum.htm /=idnum serves /paste/idnum.htm /paste/idnum redirects to /~idnum (to update any old... (0 Replies)
Discussion started by: phillips1012
0 Replies

5. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

8. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question