473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Copying a string from file

6
Hi there.
I'm new to Linux, I'm using the 12.04 LTS distribution and I'm having kind of a hard time here.
I have a file which contains information in the fasta format (a format for biologists), which looks like this:

>Id string_of_variable_length ~Number~Id2
[string of thousands of characters]

>Id string_of_variable_length ~Number~Id2
[string of thousands of characters]

>Id string_of_variable_length ~Number~Id2
[string of thousands of characters]

where > is a new entry and contains a header in the first line and a protein/nucleic acid sequence in the lines below.
Now, everything is unique for each entry except for the tilde, which appears before a number of variable digits and before a second Id for each entry.

I'm interested in making a new file containing a list of the Id2 field (which is also of variable length) and I thought I could use grep, but I've tried and don't know how to tell it to copy only what appears after the second tilde. Any advice on how to perform that task is greatly appreciated. Even if you could point me in the right direction,
maybe grep isn't the best way to do it?

Thanks in advance!
Apr 2 '14 #1
1 1541
Banfa
9,065 Expert Mod 8TB
Use grep and sed (or at least I would) The grep isolates the lines you are interested, you pipe the output into sed which picks out the actual item of interest form the line.

NOTE OF CAUTION: I'm not sure if ~ needs to be escaped as \~ in regular expressions but I think not.

Something line this should do it.

grep -E ".*~.*~" | sed "s/.*~.*~\(.*\)/\1/g"
Apr 2 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Richard Jonas | last post by:
I've written a Windows Application in C#.net that runs in the background and silently archives files to a network drive (using the System.IO.File.Copy function). Sometimes, users may run this...
7
by: Frank Rizzo | last post by:
Hello, I've asked this question in the languages.vb group, but got no response, so I'll try my luck here. My app needs to copy a file from a local folder to a network share. The network share...
8
by: Randy | last post by:
Hi, is it possible to show the progress of a big file being copied e.g. in a "progressbar"? I tried to use file.copy - but this seems to make no sense :-( Thanks in advance, Randy
8
by: John Smith | last post by:
Hi folks, I know how to place text into the user's clipboard: Clipboard.SetDataObject("My Copied Text"); but how do I place a file in there? So, if I have a file C:\test.txt, how can I place...
0
by: Frank Rizzo | last post by:
Hello, my app needs to copy a file on a network share. The network share is accessible via a domain ID, which has all possible folder rights assigned to it. I am using the impersonation code...
2
by: .Net Believer | last post by:
I using the routine below to copy file to a network drive for a regular backup process. Before calling this routine I using another function to check the presence of the LAN connection and the...
25
by: Mark | last post by:
when i run the following code ifstream fin("scenario.chk",ios::in | ios::binary); ofstream fout("out.chk",ios::out | ios::binary); while( !fin.eof() ) { fout.put(fin.get()); }
8
by: Jared Wiltshire | last post by:
Hi, I've written the following code to copy one files contents line by line into another file. However I'm a bit dubious about using the infinite loop to do this. ifstream infile("File1.txt");...
0
by: AmyHanson | last post by:
I am new to mobile development and am having some trouble sources for the tasks I need to perform. I have been looking around and I can find plenty of information on copying the file initiating on...
2
by: raylopez99 | last post by:
Beware newbies: I spent a day before I figured this out: copying a bitmap (image) file to file is not quite like copying a text file--you have to do some tricks (see below), like using a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.