Insert underscore in place of column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert underscore in place of column
# 1  
Old 08-13-2012
Insert underscore in place of column

Hi

I tried to put underscore in place of column in a big file with lots of oclumns using the programm

Code:
  sed 's/[\t]/_/g'

Its showing error
HTML Code:
bash-3.2$ sed 's/[\t]/_/g'saradrugbankgenedrugnewlist.txt >saradrugbankgenedrugnewlist3.txt
sed: -e expression #1, char 11: unknown option to `s'

if input is like these so many columns


Code:
AST3  GUD  GDY

JHF    HGA   HAY

I want output shuld be

Code:
AST3_GUD_GDY

JHF_HGA_HAY


Kindly guide
# 2  
Old 08-13-2012
Try (GNU sed):
Code:
$ sed 's/[ \t]\+/_/g' infile
AST3_GUD_GDY

JHF_HGA_HAY

# 3  
Old 08-13-2012
I think you're just missing the space before the filename...
# 4  
Old 08-13-2012
its placing underscore even if there is some space within a columns which I dont want

for eg

if there are 3 columns
Code:
AST not available  sht

its shows
Code:
AST_not_available_sht

but I want it shuld show

Code:
AST_not available_sht

so there is an error.
# 5  
Old 08-13-2012
That's a new aspect. Please show a representative input example and a related output example. Also describe the rules when and where something should be substituted to avoid that people keep guessing or requirements are different inbetween posts, thanks.
# 6  
Old 08-13-2012
Hi

As I mentioned above only column has to be replce with underscore no change within the column has to be made and I made it clear by citing above sample example no other chsnge has to be made. Kindly guide if possible.
# 7  
Old 08-13-2012
manigrover, in your 1st example you want all spaces replaced by an underscore. In the second example it seems you have this:
Code:
AST not available  sht

This is a very limited excerpt. From a look of awk this has 4 columns, not 3, since a blank, space and tabs form a field separator and in your input there is nothing but blanks as separator.
One could parse that if the line contains "not available", that this is protected from substitution, but I bet you have more than this line - else you would not need a script.

So to help you describing your input, is there just 3 columns usually and when it is 4, then there is the string "not available" in there or is there even more kinds of different lines.
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