write string of characters to file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers write string of characters to file
# 1  
Old 05-07-2009
write string of characters to file

Hi,
I have a text file with a very long string of characters, like "ACGCTTGCAA...", and I want to make another file with 36 characters from this string file every 4 lines like:

character of position 1 to position 36 of the string file, position 2-37, position 3-38 ... position length((string)-35)-length(string).
And in the other lines of the file write always the same strings like below:

@read
AACCCAGTAAGTCACAGTGCANCAAACTTGTTTATT
+read
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@read
ACCCAGTAAGTCACAGTGCANCAAACTTGTTTATTC
+read
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@read
CCCAGTAAGTCACAGTGCANCAAACTTGTTTATTCA
+read
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So my question is, how can I do it?
# 2  
Old 05-07-2009
Looks like DNA bases...

Code:
getconf LINE_MAX

This shows the longest possible string command line utilties can read from a file without err. On a lot of systems this is 2048. If your DNA-base string is longer than 2048 characters then you need C or perl, or python.

less than 2048:
Code:
awk ' { str=$0}
END{
 for(i=1; length(str) - i > 35; i++)
 {
	printf("%s\n%s\n%s\n%s\n",
		"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
		"@read",
		substr(str, i, 36),		
		"+read"
		)
 } } ' dnastringfile


Last edited by jim mcnamara; 05-07-2009 at 01:56 PM..
# 3  
Old 05-07-2009
Thanks for the info.
And what would be the code if each line would have only 36 characters like:

agcgagcgtttgagctggctgaacgtttgcagtcgt
tggcttgagctggctgaacgtttgcagtccgacgac

I guess now the code would be a bit more complicated since for example with the read from position 2 to 37 I would have to fetch characters from line 1 and 2.


Best regards and thanks in advance,
Joćo
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting characters after a given string and reporting the characters in the row below --sed

I have this fastq file: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGGGGGGGGGGGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCA +test-1 GGGGGGGGGGGGGGGGGCCGGGGGFF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8... (10 Replies)
Discussion started by: Xterra
10 Replies

2. Shell Programming and Scripting

Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file. Kindly provide your input. File is like below Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Discussion started by: Raysf
2 Replies

3. Shell Programming and Scripting

Regex to split a string and write the output in another file.

hi, i am trying to write a script to generate ouput in the following format: ##### buildappi abcd_sh nodebug.##### ##### buildappi ijk_sh nodebug.##### The given string is as follows: xtopSharedDLLs = "abcd_sh def_sh ijk_sh " \ + "jkl_sh any_sh... (15 Replies)
Discussion started by: Rashid Khan
15 Replies

4. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

5. Shell Programming and Scripting

Write string variables to file

I have the following: #! /bin/bash foo="bar" this="that" vars="foovar=$foo\n\ thisvar=$this\n" I want to write the following to a file: foovar="bar" thisvar="that" Then in another script, I pull this file, and loop through it: while read line; do eval $line done <... (3 Replies)
Discussion started by: Validatorian
3 Replies

6. Shell Programming and Scripting

Extract string from a file & write to a new file (Perl)

Hi, This is the first time playing around with perl and need some help. Assuming if i have a line of text that looks like this: Date/Time=Nov 18 17:12:11;Device Name=192.168.1.1;Device IP=192.168.1.1;Device Class=IDS;Source IP=155.212.212.111;Source Name=UNKNOWN;Source Port=1679... (3 Replies)
Discussion started by: LuckyGuy
3 Replies

7. Shell Programming and Scripting

How to delete a string pattern in a file and write back to the same file

I have a control file which looks like this LOAD DATA INFILE '/array/data/data_Finished_T5_col_change/home/oracle/emp.dat' PRESERVE BLANKS INTO TABLE SCOTT.EMP FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS (................. ..................) How can i edit the... (1 Reply)
Discussion started by: mwrg
1 Replies

8. UNIX for Dummies Questions & Answers

How to write a string with special characters to a file

Hi, I want to erase the contents of a file and write a sql query into the file. "" > tmp.txt "select count\(\*\) \"Names\" from v\$ground where status\=\'Invalid\'\;" > tmp.txt doesnt work, pls help. (2 Replies)
Discussion started by: happyrain
2 Replies

9. Shell Programming and Scripting

line contains a string write to new file otherwise append

hi i have the following function, reading file line by line, if line contains "Change state" i need to cut some fields otherwise i need to append the total line to the new file function parse() { while read LINE do echo $LINE |grep -q "Change state" if then echo $LINE |grep -q... (1 Reply)
Discussion started by: Satyak
1 Replies

10. Shell Programming and Scripting

Can I write a string into file from shell?

Hi , If I used this wc -l *.dat ,it will count number of line in these files like this 1234 test1.dat 2345 test2.dat 3456 test3.dat 7035 total can I add '|'(pipe) in the middle of those number and string like this 1234|test1.dat 2345|test2.dat 3456|test3.dat Thanks in advance. (10 Replies)
Discussion started by: guitaroa47
10 Replies
Login or Register to Ask a Question