Deleting certain new lines from a file with shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting certain new lines from a file with shell
# 1  
Old 02-16-2011
Deleting certain new lines from a file with shell

Good morning!!! Im a newbie with shell programing and i was wondering if there is a way to delete certain new lines from a file, here is an example of my current file:
Code:
>seq_0
GTGAGATTGCTAATGAGCTGCTTTTAGGGGGCGTGTTGTGCTTGCTTTCC
AACTTTTCTAGATTGATTCTACGCTGCCTCCAGCAGCCACCCCTCCCATC
ACCATTCCCATCACCATCCAGTCCCGTTGGCTCCCAGTCACAGTATTACA
CGTATGCAAATTAAGCCGAAGTTCAATTGCGACCGCAGCAACAACACGAT
>seq_1
TTATGTCTCGATTCCAGCTAAATTGTCGCCTAAAGACGCCTCCGCCGGCG
TTGAGCGCCGAGCAGCATCTGGCACGCATCGAGGTTTTCAATTCGCTGGC
CGTGACAGCACCCCAAATCGAGGTGGACCGCCTGCGCTACGATAGGCGGC
ACAACATGAGCGGTAAGTGGATGCCACCAGCGGTTGGATCTGTGGGCGTG
GCAGTGGGAGTGGGAGTACGTGCCAGTCACGGCTGCCGTACCACCCGAAA
TCTGGTAAACAACGCTAATGCCACATGGTCACACTCCGGGACAGCTGATT
TGAAGAAGAAGAAGCAGCACGTGCACGTTGTTGTCAAATTTCAAATTAAC
TTTATTTGAAGCCAGCTTTTAAGTTAATTTCATCTTGCTGACACATCAAG
>seq_2
ACCAAAATAAATCTGGGAACTGAATAATCGAAAATAACTGGATGTGCATC
ATAAGATCTTCTTTTGAAGACTGACTACAGTTTGCAGCTCAGCGAGCTCG
GGCCGGCAACTCAAGCCGGTCAACTCAAGTCAGGCGCCAATTCGCTGCTC
CCACTCGCTCAGCTCTCTCAGTCACTCAAAATGGCAACGAGAGCAGAACG
GTTCTTTTGCAAAATACTTTATGACCGGAGCAGAAGCAGAATCGGACCTC
TGTCGCGGTCGCAGTCGCTGCCAGTGCTGACGGCGCTGTTGCGGCCGACG

And i was wondering if i can delete all the new lines from the letters sequences, so i can get one line with the >seq_# and only one line for all the letters, example:
Code:
>seq_0
GTGAGATTGCTAATGAGCTGCTTTTAGGGGGCGTGTTGTGCTTGCTTTCCAACTTTTCTAGATTGA...
>seq_1
TTATGTCTCGATTCCAGCTAAATTGTCGCCTAAAGACGCCTCCGCCGGCGTTGAGCGCCGAGCAGC...
>seq_2
ACCAAAATAAATCTGGGAACTGAATAATCGAAAATAACTGGATGTGCATCATAAGATCTTCTTTTG...

Thanks for your help Smilie

Last edited by Scott; 02-16-2011 at 02:11 PM.. Reason: Please use code tags
# 2  
Old 02-16-2011
Code:
nawk '/^>/{printf("%c%s\n",(FNR==1)?"":"\n",$0);next}{printf $0}END{print}' myFile

# 3  
Old 02-16-2011
Thanks!!! im trying to save it to a new file

Code:
 
nawk '/^>/{printf("%c%s\n",(FNR==1)?"":"\n",$0);next}{printf $0}END{print}' myFile >> newfile

But i cant get it recognized as a text file, am i doing something wrong? thanks!
# 4  
Old 02-16-2011
Quote:
Originally Posted by machalita
Thanks!!! im trying to save it to a new file

Code:
 
nawk '/^>/{printf("%c%s\n",(FNR==1)?"":"\n",$0);next}{printf $0}END{print}' myFile >> newfile

But i cant get it recognized as a text file, am i doing something wrong? thanks!
Hmmm... I'm having hard time understanding what's wrong - the above looks fine.
What error/warning messages are you seeing?
Anything in the 'newfile'?
# 5  
Old 02-16-2011
The new file its not being recognized as a text file, when i try to open it, i get the error: Gedit has not been able to detect the character coding, please check that you are not trying to open a binary file.
# 6  
Old 02-16-2011
Quote:
Originally Posted by machalita
The new file its not being recognized as a text file, when i try to open it, i get the error: Gedit has not been able to detect the character coding, please check that you are not trying to open a binary file.
Sorry, don't know much about Gedit.
Can you 'cat' a file or use other editor?
# 7  
Old 02-16-2011
Can you change >> newfile to > newfile while you are at it?

And show the output of file myFile (the input file)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

deleting few lines from a file dynamically

here is the part of the code var1="replicate-ignore-db" var2="replicate-same-server-id" var3="skip-slave-start" var4="report-host" var5="master-host" var6="master-user" var7="master-password" var8="master-port" #code below deleted paramters as above if exists in my.cnf for i in 1 2 3 4... (4 Replies)
Discussion started by: vivek d r
4 Replies

2. Shell Programming and Scripting

deleting specific lines in a file

Hello, I have a file like: 26-07-2011 sunz02 message1 26-07-2011 sunz02 message2 26-07-2011 sunz02 message3 15-07-2011 sunz02 message1 15-07-2011 sunz02 message2 15-07-2011 sunz02 message3... (5 Replies)
Discussion started by: asanchez
5 Replies

3. Shell Programming and Scripting

Deleting specific lines in a file

Hello, I have a file like this one: 03-07-2011 sunz02 message1 03-07-2011 sunz02 message2 03-07-2011 sunz02 message3 01-07-2011 sunz02 message1 01-07-2011 sunz02 message2 01-07-2011 sunz02 ... (1 Reply)
Discussion started by: asanchez
1 Replies

4. Shell Programming and Scripting

Shell deleting specific lines

Hi, I'am working under unix solaris I have a text file with set of lines, each set of lines (BLOCK) have three fixed lines : Between SECND line and THEND we have N lines, N differ from a block to another sample : i have to make a script wich delete each 3 fixed lines if N=0... (3 Replies)
Discussion started by: salbanito
3 Replies

5. Shell Programming and Scripting

deleting the lines at the end of the file.

I have a text file with two coulmn first column is just used in to show the line number, these line number are not there in the real file. I want to delete the line 16(in this file) here, even tough there is no data inside it . this empty line is causing me a problem by throwing me garbage... (12 Replies)
Discussion started by: shashi792
12 Replies

6. Shell Programming and Scripting

deleting lines from file

We have a server that logs transactions to a file. I want to write a script that will delete the first 50 lines of the file daily without renameing the file or moving the file. (8 Replies)
Discussion started by: daveisme
8 Replies

7. UNIX for Advanced & Expert Users

Deleting lines from a file

How I can delete 100 lines anywhere in a file without opening a file and without renaming the file. (11 Replies)
Discussion started by: Nirgude07
11 Replies

8. UNIX for Dummies Questions & Answers

Deleting whole lines from a file

I have a file with 65 sets of 35 coordinates, and would like to isolate these coordinates so that I can easily copy the coordinates to another file. The problem is, I've got a 9 line header before each set of coordinates (so each set is 44 lines long). There are a zillion threads out there about... (3 Replies)
Discussion started by: red baron
3 Replies

9. Shell Programming and Scripting

Deleting lines in a file

How do I delete all the lines after the line containing text ***DISCLOSURES*** . I want to delete this line too. Thank you (2 Replies)
Discussion started by: reachsamir
2 Replies

10. Shell Programming and Scripting

Deleting last 2 lines from the file.

Hi I have a file & always I need to remove or delete last 2 lines from that file. So in a file if I have 10 lines then it should return me first 8 lines. Can someone help me? (4 Replies)
Discussion started by: videsh77
4 Replies
Login or Register to Ask a Question