Breaking up a text file into lines


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Breaking up a text file into lines
# 1  
Old 08-26-2011
Breaking up a text file into lines

Hi,

I have a space delimited text file that looks like the following:

BUD31 YRI 2e-06:CXorf15 YRI 3e-06:CREB1 YRI 4e-06
FLJ21438 CEU 3e-07:ETS1 CEU 8e-07:FGD3 CEU 2e-06

I want to modify the text file so that everytime there is a ":", a new line is introduced so that the document looks like the following:

BUD31 YRI 2e-06
CXorf15 YRI 3e-06
CREB1 YRI 4e-06
FLJ21438 CEU 3e-07
ETS1 CEU 8e-07
FGD3 CEU 2e-06

How do I go about doing this? Thanks!
# 2  
Old 08-26-2011
Like this?

Code:
< infile sed 's/:/\n/g'

# 3  
Old 08-26-2011
Code:
tr : '\n' <infile >outfile

Regards,
Alister
# 4  
Old 08-26-2011
or:


Code:
$ cat yourinputfile|tr -s ":" "\n"

and the output from above:

BUD31 YRI 2e-06
CXorf15 YRI 3e-06
CREB1 YRI 4e-06
FLJ21438 CEU 3e-07
ETS1 CEU 8e-07
FGD3 CEU 2e-06
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

3. Shell Programming and Scripting

Read n lines from a text files getting n from within the text file

I dont even have a sample script cause I dont know where to start from. My data lookes like this > sat#16 #data: 15 site:UNZA baseline: 205.9151 0.008 -165.2465 35.8109 40.6685 21.9148 121.1446 26.4629 -18.4976 33.8722 0.017 -165.2243 48.2201 40.6908 ... (8 Replies)
Discussion started by: malandisa
8 Replies

4. Shell Programming and Scripting

How to delete lines of a text file based on another text file?

I have 2 TXT files with with 8 columns in them(tab separated). First file has 2000 entries whereas 2nd file has 300 entries. The first file has ALL the lines of second file. Now I need to remove those 300 lines (which are in both files) from first file so that first file's line count become... (2 Replies)
Discussion started by: prvnrk
2 Replies

5. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

Breaking lines which contains more than 50 characters in a file

Hi, I have a file which contains many lines. Some of them are longer than 50 chars. I want to break those lines but I don't want to break words, e.g. the file This is an exemplary text which should be broken aaaaaa bbbbb ccccc This is the second line This line should also be broken... (3 Replies)
Discussion started by: wenclu
3 Replies

7. UNIX for Dummies Questions & Answers

How to grep multiple lines from a text file using another text file?

I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

8. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

9. Shell Programming and Scripting

how to get the no. of lines in a text file

Hi, I want to count the no. of lines in a text file and print only the count(without file name) in another file with the prefix 'Count:'. I'm able to count the no. of lines present in the file using wc -l <filename> but i have to subtract one from the count and print as i dont need to... (8 Replies)
Discussion started by: vimalr
8 Replies

10. Shell Programming and Scripting

Breaking long lines into (characters, newline, space) groups

Hello, I am currently trying to edit an ldif file. The ldif specification states that a newline followed by a space indicates the subsequent line is a continuation of the line. So, in order to search and replace properly and edit the file, I open the file in textwrangler, search for "\r " and... (14 Replies)
Discussion started by: rowie718
14 Replies
Login or Register to Ask a Question