How to recognize a string and move it within a line?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to recognize a string and move it within a line?
# 1  
Old 05-08-2009
How to recognize a string and move it within a line?

Guys, can you pls help?.
My need is to find a string in a line, cut it and append to the end of the line where it was found. I guess the sed command can handle this, but how?..

e.g. in the line

AZOAR1_1_PE2569,HBG316802,partial,Q5P1X0,"Dihydrolipoamide dehydrogenase protein";"Glutathione reductase protein"

I need to move “,partial” to the end to get

AZOAR1_1_PE2569,HBG316802,Q5P1X0,"Dihydrolipoamide dehydrogenase protein";"Glutathione reductase protein",partial

Thanks in advance!
# 2  
Old 05-08-2009
Code:
echo 'AZOAR1_1_PE2569,HBG316802,partial,Q5P1X0,"Dihydrolipoamide dehydrogenase protein";"Glutathione reductase protein"' | sed 's/\(.*\),partial\(.*\)/\1\2,partial/'

# 3  
Old 05-08-2009
another way
Code:
# echo 'AZOAR1_1_PE2569,HBG316802,partial,Q5P1X0,"Dihydrolipoamide dehydrogenase protein";"Glutathione reductase protein"' | sed 's/.*\(,partial\).*/&\1/;s/,partial//'

# 4  
Old 05-08-2009
Gorgeous Smilie i love unix. Many thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

How to add a new string at the end of line by searching a string on the same line?

Hi, I have a file which is an extract of jil codes of all autosys jobs in our server. Sample jil code: ************************** permission:gx,wx date_conditions:yes days_of_week:all start_times:"05:00" condition: notrunning(appDev#box#ProductLoad)... (1 Reply)
Discussion started by: raghavendra
1 Replies

2. UNIX for Dummies Questions & Answers

Convert UNIX text file in Windows to recognize line breaks

Hi all, I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this? Or just reinsert thousands of line breaks again :eek: ? (2 Replies)
Discussion started by: frys_hp
2 Replies

3. Windows & DOS: Issues & Discussions

Convert UNIX text file in Windows to recognize line breaks

Hmmm I think I found the correct subforum to ask my question... I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this?... (1 Reply)
Discussion started by: frys_hp
1 Replies

4. Shell Programming and Scripting

move string in a text file

Hi all! I need some help in changing a text file. I have the following text file: 1,050406259214736,00010,5000,MZM,V050,20131231,EMIG 2,Available,20061126T10:40:15,vs,, 2,Used,20110813T12:32:35,,825351585,1411012901443027 1,050410256649750,00010,5000,MZM,V050,20131231,EMIG ... (2 Replies)
Discussion started by: fretagi
2 Replies

5. Shell Programming and Scripting

How does a shell script recognize the end of a line?

Hi friends , I want to know how does a shell script recognize the end of a line? . i have hunddres of proccedure to test where i want to ingnore the comments which starts with "--" .. it can start from the middle of the lines also. for example:: select * from table1; -- getting... (5 Replies)
Discussion started by: neelmani
5 Replies

6. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

7. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

8. Shell Programming and Scripting

Move lines above a line onto one line

So say I have the file: john london 24 male ======== jane london 22 female ======== mike 23 ======== Bob how do i get the information i need on one line as such: (5 Replies)
Discussion started by: linuxkid
5 Replies

9. Shell Programming and Scripting

awk script to move a line after the matched pattern line

I have the following text format in a file which lists the question first and then 5 choices after that the explanantion and finally the answer. 1.The amount of time it takes for most of a worker’s occupational knowledge and skills to become obsolete has been declining because of the... (2 Replies)
Discussion started by: nanchil_guy
2 Replies

10. Shell Programming and Scripting

move to a particular line

Hi, I need to create a report in unix by moving to specified lines and specified positions and print some strings etc.. for eg: i need to print a string on 15th line and 7th position of a file. Please suggest. Thanks, Mohan (3 Replies)
Discussion started by: mohanpadamata
3 Replies
Login or Register to Ask a Question