Process alternate lines in awk/sed/perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process alternate lines in awk/sed/perl
# 1  
Old 07-15-2013
Process alternate lines in awk/sed/perl

hi..

i have a fasta file with the following format

Code:
>sequence1
CCGGTTTTCGATTTGGTTTGACT
>sequence2
AAAGTGCCGCCAGGTTTTGAGTGT
>sequence3
AGTGCCGCAGAGTTTGTAGTGT

Now, i want to read alternate line and add "GGGGGGGGGGG" to end of every sequence

Desired output:

Code:
>sequence1
CCGGTTTTCGATTTGGTTTGACTGGGGGGGGGGG
>sequence2
AAAGTGCCGCCAGGTTTTGAGTGTGGGGGGGGGGG
>sequence3
AGTGCCGCAGAGTTTGTAGTGTGGGGGGGGGGG

Moderator's Comments:
Mod Comment Please use CODE tags to mark code, input, and output samples.


---------- Post updated at 11:06 PM ---------- Previous update was at 11:00 PM ----------

---------- Post updated at 11:06 PM ---------- Previous update was at 11:06 PM ----------

I was trying the following command and missed a simple flower brace and struggling. Now i figured it out and working fine.. thanks..
Code:
awk 'NR % 2 {print} !(NR % 2) {print $0"GGGGGGGGG"}' seq.fa


Last edited by Don Cragun; 07-15-2013 at 12:04 AM.. Reason: Add CODE tags
# 2  
Old 07-15-2013
Try something like:
Code:
sed '/^[^>]/s/$/GGGGGGGGGGG/' fasta.txt

# 3  
Old 07-15-2013
try..

Code:
 
printf "%s\n%sGGGGGGGGGGG\n" $(cat filename)

# 4  
Old 07-15-2013
Quote:
Originally Posted by vidyadhar85
try..

Code:
 
printf "%s\n%sGGGGGGGGGGG\n" $(cat filename)

This isn't a robust approach under any circumstance. When dealing with possibly large amounts of bioinformatics data, it's even less so.

Regards,
Alister
# 5  
Old 07-16-2013
Quote:
Originally Posted by alister
This isn't a robust approach under any circumstance. When dealing with possibly large amounts of bioinformatics data, it's even less so.

Regards,
Alister
Thanks..

I never mentioned its "THE BEST" option I wanted to show if one have small amount of date there is no need to use fancy sed/awk alays Smilie

Its upto one how he/she read/take it..

Regards,
Vidya
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/awk/perl substitution with multiple lines

OSX I have been grinding my teeth on a portion of code. I am building a bash script that edits a html email template. In the template, I have place holders for SED (or whatever program is appropriate) to use as anchors for find and replace, with user defined corresponding html code. The HTML code... (3 Replies)
Discussion started by: sudo
3 Replies

2. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

3. Shell Programming and Scripting

Using sed, awk or perl to remove substring of all lines except the first

Greetings All, I would like to find all occurences of a pattern and delete a substring from the all matching lines EXCEPT the first. For example: 1234::group:user1,user2,user3,blah1,blah2,blah3 2222::othergroup:user9,user8 4444::othergroup2:user3,blah,blah,user1 1234::group3:user5,user1 ... (11 Replies)
Discussion started by: jacksolm
11 Replies

4. Shell Programming and Scripting

Sed/awk/perl command to replace pattern in multiple lines

Hi I know sed and awk has options to give range of line numbers, but I need to replace pattern in specific lines Something like sed -e '1s,14s,26s/pattern/new pattern/' file name Can somebody help me in this.... I am fine with see/awk/perl Thank you in advance (9 Replies)
Discussion started by: dani777
9 Replies

5. Programming

Perl : joining alternate lines

Hi, I need to join every alternate line in a file for eg:input file $ cat abc abc def ghi jkloutput abc def ghi jklcode i wrote for this $ cat add_line.pl #!/usr/bin/perl -w my $count=1; #my $line=undef; my @mem_line; my $i=0; my $x=0; (2 Replies)
Discussion started by: sam05121988
2 Replies

6. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

7. Shell Programming and Scripting

Delete Lines : after pattern1 and between pattern2 and pattern3 using awk/sed/perl

Hi I need to delete lines from a file which are after pattern1 and between pattern 2 and patter3, as below: aaaaaaaa bbbbbbbb pattern1 cdededed ddededed pattern2 fefefefe <-----Delete this line efefefef <-----Delete this line pattern3 adsffdsd huaserew Please can you suggest... (6 Replies)
Discussion started by: vk2012
6 Replies

8. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

9. Shell Programming and Scripting

Command to remove duplicate lines with perl,sed,awk

Input: hello hello hello hello monkey donkey hello hello drink dance drink Output should be: hello hello monkey donkey drink dance (9 Replies)
Discussion started by: cola
9 Replies

10. Shell Programming and Scripting

alternate lines

Hi, I'm new to Unix. I want to read the all the lines from a text file and write the alternate lines into another file. Please give me a shell script solution. file1 ----- one two three four five six seven newfile(it should contain the alternate lines from the file1) ------- one... (6 Replies)
Discussion started by: pstanand
6 Replies
Login or Register to Ask a Question