Insert underscore in place of column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert underscore in place of column
# 8  
Old 08-13-2012
Actually there are many other columns in the file with words seprated by space the only which i have to do is only replace column which i think is tab seprated to be replaced by underscore not the words within column so input can be 5 column
Code:
AST  aluminum tungstate   Al    available     confirm

GST   guanine tungstate     Gn     not availble    not confirmed


And i have place 4 underscore because there are only 4 place column lines are prrsent
# 9  
Old 08-13-2012
Ok, so it looks like a blank, spaces or tabs should be replaced by 1 underscore, but the only exception is "not available" and "not confirmed". Correct?
Is this a database dump? How is the file created?
# 10  
Old 08-13-2012
No there might be other words its not just not confirmed or not availableble

I came to know that column is nothing but tab separation so i feel if tab is replaced by underscore it may wrk because i have to replace column not double space/blank/space jst column which seems equals to tab as far as I read till now.
# 11  
Old 08-13-2012
You can replace a tab or more of them by an underscore, but as long as you just "feel" or "think" they are tab separated, this will be not exact. If it is not the case, you will have a wrong output.

You did not answer how the file is being produced. I do not ask again even though you could maybe get a better field separator by this at this stage. Anyway:

Code:
$ od -c infile
0000000   A   S   T  \t   a   l   u   m   i   n   u   m  \t   t   u   n
0000020   g   s   t   a   t   e  \t  \t   A   l  \t   a   v   a   i   l
0000040   a   b   l   e  \t  \t   c   o   n   f   i   r   m  \n  \n   G
0000060   S   T  \t  \t   g   u   a   n   i   n   e  \t   t   u   n   g
0000100   s   t   a   t   e  \t  \t  \t   G   n  \t   n   o   t       a
0000120   v   a   i   l   a   b   l   e  \t  \t   n   o   t       c   o
0000140   n   f   i   r   m   e   d  \n
0000150
$ cat infile
AST     aluminum        tungstate               Al      available               confirm

GST             guanine tungstate                       Gn      not available           not confirmed
$ sed 's/\t\+/_/g' infile
AST_aluminum_tungstate_Al_available_confirm

GST_guanine_tungstate_Gn_not available_not confirmed

# 12  
Old 08-13-2012
Hi

The file is from a database. Actually i studied once column is nothing but tab separation and in the code mentioned above here is undrrscore between aluminium and tungstate which I dont want as both words are in same column.
# 13  
Old 08-13-2012
Ok, I have just placed some tabs between the input columns as I thought it is correct. You can change it yourself in the input on your own. Anyways as it is just an example, the code still applies.
If it is from a database, usually you can give the database export/dump a delimeter (which is strongly recommended), let's say a semicolon or some other unique character, that would make handling such files much easier. We would not have to guess heh.
# 14  
Old 08-14-2012
Hi

My input file is like this:
Code:
000000   F   H   I   T      \t   A   d   e   n   o   s   i   n   e    
0000020   M   o   n   o   t   u   n   g   s   t   a   t   e  \t   N   o
0000040   t       A   v   a   i   l   a   b   l   e       C   A   D   ,
0000060   H   T   ,   H   T   ,   T   2   D  \t   A   d   o   -   P   -
0000100   C   h   2   -   P   -   P   s   -   A   d   o  \t   N   o   t
0000120       A   v   a   i   l   a   b   l   e       C   A   D   ,   H
0000140   T   ,   H   T   ,   T   2   D  \n   C   S      \t   T   r   i
0000160   f   l   u   o   r   o   a   c   e   t   o   n   y   l       C
0000200   o   e   n   z   y   m   e       A  \t   N   o   t       A   v
0000220   a   i   l   a   b   l   e       C   A   D   ,   C   A   D   ,
0000240   T   1   D  \t   A   l   p   h   a   -   F   l   u   o   r   o
0000260   -   C   a   r   b   o   x   y   m   e   t   h   y   l   d   e
0000300   t   h   i   a       C   o   e   n   z   y   m   e       a    
0000320   C   o   m   p   l   e   x  \t   N   o   t       A   v   a   i
0000340   l   a   b   l   e       C   A   D   ,   C   A   D   ,   T   1
0000360   D  \t   N   i   t   r   o   m   e   t   h   y   l   d   e   t
0000400   h   i   a       C   o   e   n   z   y   m   e       A  \t   N
0000420   o   t       A   v   a   i   l   a   b   l   e       C   A   D
0000440   ,   C   A   D   ,   T   1   D  \n   C   H   R   M   1      \t
0000460   T   r   o   s   p   i   u   m  \t   S   a   n   c   t   u   r
0000500   a       T   2   D  \t   O   x   y   p   h   e   n   o   n   i
0000520   u   m  \t   A   n   t   r   e   n   y   l       T   2   D  \t
0000540   P   i   r   e   n   z   e   p   i   n   e  \t   B   i   s   v
0000560   a   n   i   l       T   2   D  \t   C   l   i   d   i   n   i
0000600   u   m  \t   Q   u   a   r   z   a   n       T   2   D  \t   P
0000620   r   o   p   a   n   t   h   e   l   i   n   e  \t   P   r   o
0000640   -   B   a   n   t   h   i   n   e       T   2   D  \t   C   y
0000660   c   r   i   m   i   n   e  \t   P   a   g   i   t   a   n   e
0000700       T   2   D  \t   C   y   c   l   o   p   e   n   t   o   l
0000720   a   t   e  \t   A   K   -   P   e   n   t   o   l   a   t   e
0000740       T   2   D  \t   G   l   y   c   o   p   y   r   r   o   l
0000760   a   t   e  \t   A   s   e   c   r   y   l       T   2   D  \t
0001000   A   r   e   c   o   l   i   n   e  \t   N   o   t       A   v
0001020   a   i   l   a   b   l   e       T   2   D  \n   P   D   E   3
0001040   A      \t   M   i   l   r   i   n   o   n   e  \t   C   o   r
0001060   o   t   r   o   p       H   T  \t   A   n   a   g   r   e   l
0001100   i   d   e  \t   A   g   r   y   l   i   n       H   T  \t   C
0001120   i   l   o   s   t   a   z   o   l  \t   P   l   e   t   a   a
0001140   l       H   T  \t   E   n   o   x   i   m   o   n   e  \t   P
0001160   e   r   f   a   n       H   T  \n   P   D   E   3   B      \t
0001200 001   5   r 001   -   6   - 001   4   - 001 001   2   - 001   3
0001220   -   I   o   d   o   b   e   n   z   y   l 001   -   3   -   O
0001240   x   o   c   y   c   l   o   h   e   x   -   1   -   E   n   -

I have to put underscore in place of column but file is so big that I can not place tab at all places where is column adn then change is to underscore . Kindly guide if possible.

And, I am not aware of export/dump a delimiter function for the whole file of a database.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

2. Shell Programming and Scripting

How to place Record in a row as a column name?

Hi, I want to know how to place a particular field availble in a record as the columnname. Name,Sam,Age,13,School, StJohn Name,Rita,Age,12,School, StMichael, Name,John,Age,14,School, StAnthony I want the output as Name Age School Sam 13 StJohn Rita 12 StMichael John 14... (6 Replies)
Discussion started by: sidnow
6 Replies

3. Shell Programming and Scripting

Unable to get the Specific column with 2 decimal place

Hi, I have an issue converting decimal places of a particular column, i am using below script to get the output, but the output is not generating in desired format. awk -F"," 'BEGIN{OFS=","}{if(NR==0)getline;if ($7 != "") {if ($7 > 0) $7=$7/100 ; {printf "%.2f"... (3 Replies)
Discussion started by: rramkrishnas
3 Replies

4. Shell Programming and Scripting

Insert data in first column(if blank) from previous line first column

Dear Team I need to insert field(which is need to taken from previous line's first field) in first column if its blank. I had tried using sed but not find the way. Detail input and output file as below. Kindly help for same. INPUT: SCGR SC DEV DEV1 NUMDEV DCP ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

5. Shell Programming and Scripting

Find regex, place on individual lines and insert blank line before

Hello, I have a file that I want to be able to insert a new line before every instance of a regex. I can get it to do this for each line that contains the regex, but not for each instance. Contents of infile: Test this 1... Test this 2... Test this 3... Test this 4... Test this... (2 Replies)
Discussion started by: deneuve01
2 Replies

6. Shell Programming and Scripting

Insert comma in place of column

Hi all, I have a file in which I have to insert commna between entries of 2 column and createa new file separated by commas not a columns if input is FHIT Adenosine Monotungstate Not Available CS Trifluoroacetonyl Coenzyme A Not Available Theo expected output is ... (5 Replies)
Discussion started by: manigrover
5 Replies

7. Shell Programming and Scripting

Insert underscore at certain places

Hi all, I have to insert underscore at certain places(places before and after PAxxx/PAxxxx entries in a big file like this ESR1 PA156 leflunomide PA450192 CHST3 PA26503 docetaxel tungstate Pa4586; thalidomide Pa34958; PAxxx/PAxxxx entries are metioned between 2 names in each row ... (4 Replies)
Discussion started by: manigrover
4 Replies

8. Shell Programming and Scripting

Insert a special character $ in place of extra spaces

Hi Experts, I have called some.txt with the following content. oracle HYRDSRVIHUB01 pts/0 TESTIHUB 07-JUN-10 CREATE TABLE TESTIHUB PHONE ... (12 Replies)
Discussion started by: naree
12 Replies

9. Shell Programming and Scripting

How to insert a string in a file at specified place?

Hi all, I want to insert a string in a specified place of a very large file. I am giving an example of the task: I love football. Above is a sentence in a file and I want to insert a string "the" between love and football. It is not sure that where this particular line exists. It has to... (4 Replies)
Discussion started by: naw_deepak
4 Replies

10. Shell Programming and Scripting

insert file 1 at a specific place of file 2

Hello, I need to search in file2 for class A : public B { and insert right after that the content of file1. I am a bit lost as to which tools (which bash functions, awk...). I should use. Thanks for some directions here. Regards (1 Reply)
Discussion started by: JCR
1 Replies
Login or Register to Ask a Question