LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-09-2013, 02:26 PM   #1
sawdusted
LQ Newbie
 
Registered: Dec 2012
Posts: 14

Rep: Reputation: Disabled
Separating line values


Guys, I have a basic question so I hope you can bear with me. I have a text file with a string of genes in one single line.

ADAM17,ADAMTS9,AKT1,APC,ARID1A,ARRDC3,BAX,BCDIN3D,BCL2,CAMK2N2,CAST,CCND1,CD274,CD44,CD82,CDKN1A,CKS 1B,COPS6,CTS

How do I transpose them so that they're one gene per line? So it would read

ADAM17
ADAMTS9
AKT1
APC
ARID1A
ARRDC3

etc etc....

Thanks. I am using basic linux command line system, No programming experience.
 
Old 09-09-2013, 02:34 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,921

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by sawdusted View Post
Guys, I have a basic question so I hope you can bear with me. I have a text file with a string of genes in one single line.
ADAM17,ADAMTS9,AKT1,APC,ARID1A,ARRDC3,BAX,BCDIN3D,BCL2,CAMK2N2,CAST,CCND1,CD274,CD44,CD82,CDKN1A,CKS 1B,COPS6,CTS

How do I transpose them so that they're one gene per line? So it would read

ADAM17
ADAMTS9
AKT1
APC
ARID1A
ARRDC3

etc etc....
Thanks. I am using basic linux command line system, No programming experience.
You've posted a couple of other threads that are similar...have you tried applying any of what you were told there to this issue? Awk can certainly do it, and sed can as well. "sed 's/,/\n//g'" will do it.
 
Old 09-09-2013, 03:25 PM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
hi sawdusted

perhaps you need to go back to the beginning, and re-state the whole of the 'problem'


consider this input
Code:
foo 7 8
bar 6 7 
foo 3 5
foo 4 3
bar 8 9
pub 5 6
club  0 3
First question is
I only want lines that contain foo
Answer
Code:
grep "foo" input
you then come back, I have this input
Code:
foo 7 8 
foo 3 5
foo 4 3
now I only want the numbers
Code:
cut -f" " 2- < input
then you want to sum the numbers
Code:
while read N1 N2;do
   echo $(( $N1 + N2 ))
done < input
all chained together
Code:
grep "foo" input | cut -d" " -f 2- | while read N1 N2;do echo $(( $N1 + N2 ));done
BUT, if asked in 'one go' you might get

Code:
awk '/foo/{print $2+$3}' input
same result , but the latter is far more efficient


Ultimately I think you would be looking at using something like perl or python to process your data
but I'm just guessing.,
 
Old 09-09-2013, 04:26 PM   #4
sawdusted
LQ Newbie
 
Registered: Dec 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
thanks for the replies guys. I have asked different questions previously. This one is new. Yes, I have applied them previous replies.

I simply want to make the names one line per name and not stringed together. My string sometimes can contain a thousand names.

I will try them out and let you know. Thank you agina.

Julian
 
Old 09-09-2013, 04:32 PM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
well the sed will work perfectly

it is just with the 'big picture' something more sophisticated might be a better fit
 
Old 09-09-2013, 04:35 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
What about the tr command?
Code:
cat file | tr , "\n" > newfile
or sed to avoid the redirection to a new file
Code:
sed -i 's:,:\n:g' file
 
Old 09-09-2013, 04:39 PM   #7
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by colucix View Post
What about the tr command?
Code:
cat file | tr , "\n" > newfile
Code:
tr , "\n" < file > newfile
no useless cat
 
Old 09-30-2013, 12:19 PM   #8
sawdusted
LQ Newbie
 
Registered: Dec 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Found the answer!
Thanks!

Last edited by sawdusted; 09-30-2013 at 07:17 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help searching for values in file then adding to line ShiGua Linux - Newbie 1 12-07-2012 11:44 AM
perl on line to take out select values casperdaghost Linux - Newbie 9 02-01-2010 01:37 AM
Search values within multiple files line to line Chrizzieej Programming 5 09-26-2008 05:11 PM
Adding values on command line.. 3saul Linux - Software 1 03-06-2006 04:01 AM
separating a comma delimited line mrobertson Programming 7 07-27-2005 02:56 PM


All times are GMT -5. The time now is 10:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration