Insert underscore in place of column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert underscore in place of column
# 22  
Old 08-14-2012
try this one
Code:
awk -F'  +' 'BEGIN{OFS="_"}{$1=$1;print}' filename

output is
Code:
FHIT_Adenosine Monotungstate_Not Available CAD,HT,HT,T2D_Ado-P-Ch2-P-Ps-Ado_Not Available CAD,HT,HT,T2D
CS_Trifluoroacetonyl Coenzyme A_Not Available CAD,CAD,T1D_Alpha-Fluoro-Carboxymethyldethia Coenzyme a Complex_Not Available CAD,CAD,T1D_

# 23  
Old 08-14-2012
Quote:
Originally Posted by Franklin52
Try this:
Code:
awk '$1=$1' FS=\t OFS=_ file

In this case, the FS for awk be "t" and not the escape sequence.
# 24  
Old 08-14-2012
Quote:
Originally Posted by elixir_sinari
In this case, the FS for awk be "t" and not the escape sequence.
Nope. I have a file with tabs in the first and the last column and spaces between a,b and c.
Code:
$ cat file
1       a  b  c 2
3               a  b  c 3
$
$ awk '$1=$1' FS=\t OFS=_ file
1_a  b  c_2
3__a  b  c_3
$

# 25  
Old 08-14-2012
Code:
$echo 'DUMMY'|awk '{print FS}' FS=\t OFS=_|od -c
0000000    t  \n
0000002

$echo 'DUMMY'|awk '{print FS}' FS=\\t OFS=_|od -c
0000000   \t  \n
0000002

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