Visit Our UNIX and Linux User Community

Modifying a line

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modifying a line
# 1  
Old 07-30-2009
Modifying a line


I am having trouble modifying this line. It is because there is a space that I dont know how to deal with.

So the file looks like this

>YM4911-Contig4 [name=joe]
>YM4915-Contig5 [name=bob]

There are two spaces between contig# and [name=x] in some files and a single space in other files. How would write a command to deal with both?

I want to modify the file so it looks like this.


This is the format that I am trying to get..

# 2  
Old 07-30-2009
this will do i guess..
sed 's/\(.*\)\(Contig[0-9]\)\(.*\)/\2/g' filename

# 3  
Old 07-30-2009
Hey that works but..

the output is like this:


How do I maintain the > so it will look like this:

# 4  
Old 07-30-2009
make small change..
sed 's/\(>\)\(.*\)\(Contig[0-9]\)\(.*\)/\1\3/g' filename

# 5  
Old 07-30-2009
thank you

I have another question.

the contig goes pass 9... so it will go up to like 5000

How does the sed line deal with that?

# 6  
Old 07-30-2009
sed 's/\(>\)\(.*\)\(Contig[0-9]*[0-9]\)\(.*\)/\1\3/g' filename

# 7  
Old 07-30-2009
With awk:

awk -F" |-" '/Contig/{print ">" $2;next}1' file

Previous Thread | Next Thread
Test Your Knowledge in Computers #380
Difficulty: Medium
Apple's macOS (previously known as Mac OS X or OS X) is a UNIX 03 registered product.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modifying bash script to take each line in a file and execute command

I need to modify a bash script to to take each line in a file and execute command. I currently have this: #!/bin/bash if ; then echo "Lipsa IP"; exit; fi i=1 ip=$1 while ; do if ; then rand=`head -$i pass_file | tail -1` user=`echo $rand | awk '{print $1}'` pass=`echo $rand | awk '{print $2}'`... (3 Replies)
Discussion started by: galford
3 Replies

2. Shell Programming and Scripting

Modifying file from command line using Perl

Hi all, I am having a slight issue updating a file using perl from the command line I need some help with. The item is: DATA_FILE_TYPE=FULL When I run the below command /usr/bin/perl -p -i -e "s/DATA_FILE_TYPE=/DATA_FILE_TYPE=APPEND/g" processfile.cfg It looks to be... (2 Replies)
Discussion started by: kstevens67
2 Replies

3. Shell Programming and Scripting

Help with modifying a filename

Hello, I have a filename that looks like this: ABC_96_20141031_041133.232468 I need to shorten only the "_2014" part of the filename to simply "_14" so the filename looks like: ABC_96_141031_041133.232468 I have to do a search for this string because there are hundreds of files and... (17 Replies)
Discussion started by: bbbngowc
17 Replies

4. Shell Programming and Scripting

Help with modifying files

Hello everyone, I have some data files, with mixed header formats. the sample for the same is: >ABCD76567.x1 AGTCGATCGTAGTCGTAGCTGT >ABCD76567.y1 AGTCGATCGTAGTCGTAGCTGT >ABCD76568.x1 pair_info:898989 AGTCGATCGTAGTCGTAGCTGT >ABCD76568.y1 pair_info:893489 AGTCGATCGTAGTCGTAGCTGT... (2 Replies)
Discussion started by: ad23
2 Replies

5. Shell Programming and Scripting

Modifying data within the same line

My file looks like this But I need to move the frequency value (Freq) to the second position, leaving intact the numbers at the top. The resulting file should look like this Thanks in advance! (3 Replies)
Discussion started by: Xterra
3 Replies

6. UNIX for Dummies Questions & Answers

Modifying a particulae data in a line contained in File

Hi, I have a file containing data: systemname/userid/password/comment systemname1/userid1/password1/comment1 systemname2/userid2/password2/comment2 I want to modify the "password" using script. Can anybody help me with this problem?:confused: (2 Replies)
Discussion started by: pgarg1989
2 Replies

7. Shell Programming and Scripting

modifying a awk line

Hi, I want to print specific columns (from 201 to 1001). The line that I am using is listed below. However I also want to print column 1. So column 1 and 201 to 1001. What modifcations do I need to make? Code: awk -F'\t' 'BEGIN {min = 201; max = 1001 }{for (i=min; i<=max; i++) printf... (5 Replies)
Discussion started by: phil_heath
5 Replies

8. Shell Programming and Scripting

Modifying file from outside

hi , I have a javascript file like this: function fnValidateId(){ var array_id = new Array("444","7888","6633","555","146562","3333","33332") var tmp_id =; var num=0; while(1) { if(tmp_id ==... (9 Replies)
Discussion started by: Sreejith_VK
9 Replies

9. Shell Programming and Scripting

can someone help me with modifying this file

Hi, I have a file which has data kind of like this. Apr 13 08:20:38 uslis10a sendmail: m3DDKSx3006432: Apr 13 08:20:38 uslis10b sendmail: m3DDKSoK006433: Apr 13 08:20:38 uslis10b sendmail: m3DDKcSo006442: Apr 13 08:20:38 uslis10c... (2 Replies)
Discussion started by: eamani_sun
2 Replies

10. IP Networking

Modifying Route

hello, I have to communicate with a distant station . But Both belong to the same area. So I do not need a gate . But when I make a traceroute, it indicates that I pass through out a gate. What can I do to establish a direct connexion between the both. (with NT ) (1 Reply)
Discussion started by: hoang
1 Replies

Featured Tech Videos