deleting from one file and putting into another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting deleting from one file and putting into another file
# 1  
Old 12-03-2009
deleting from one file and putting into another file

Hi
I have a file that is organized like this. Basically the name is indicated by >name, then on a newline there is a sequence of letters. The letters are ASKL however sometimes there are non ASKL's like U's, G's or O's. Basically what I want to do is cut out the UUUU and record them. So heres an example:
File1
Code:
>jar1
ASKLUUKK
>jar2
SAKLAKSOOKG

cutout the U's, G's and O's and record them (position along the string).

Code:
jar1 5 U
jar1 6 U
jar2 8 O
jar2 9 O
jar2 11 G

Delete the O's, G's and U's

File2
Code:
>jar1
ASKLKK
>jar2
SAKLAKSK

Then after insert 0's (zero's) into this file (into the position) - \t seperated

Code:
jar1 1  0.2
jar1 2  0.4
jar1 3  0.2
jar1 4  0.1
jar1 5  0
jar1 6  0
jar1 7  0.3
jar1 8  0.2
jar2 1  2
jar2 2  2
jar2 3  1
jar2 4  7
jar2 5  0.4
jar2 6  0.2
jar2 7  0.5
jar2 8  0
jar2 9  0
jar2 10  0.7
jar2 11  0

thanks
# 2  
Old 12-03-2009
How far did you get trying to code this?
# 3  
Old 12-03-2009
Quote:
Originally Posted by gisele_l
...Then after insert 0's (zero's) into this file (into the position) - \t seperated
Where does this file come from. What did it look like before?
# 4  
Old 12-03-2009
Code:
jar1 0.2
jar1 0.4
jar1 0.2
jar1 0.1
jar1 0.3
jar1 0.2
jar2 2
jar2 2
jar2 1
jar2 7
jar2 0.4
jar2 0.2
jar2 0.5
jar2 0.7

before it was like this
# 5  
Old 12-04-2009
Code:
$ cat file1
>jar1
ASKLUUKK
>jar2
SAKLAKSOOKG

$ cat file2
jar1 0.2
jar1 0.4
jar1 0.2
jar1 0.1
jar1 0.3
jar1 0.2
jar2 2
jar2 2
jar2 1
jar2 7
jar2 0.4
jar2 0.2
jar2 0.5
jar2 0.7

$ awk  'BEGIN {RS=">"} {split($2,a,"") 
{for (i=1;i<=length($2);i++) 
	{if (a[i]~/U|O|G/) {a[i]="0";print $1,i,a[i] > "A"} 
	 else {print $1,i,a[i] > "B"}
	}
} delete a }' file1

$ cat A
jar1 5 0
jar1 6 0
jar2 8 0
jar2 9 0
jar2 11 0

$ cat B
jar1 1 A
jar1 2 S
jar1 3 K
jar1 4 L
jar1 7 K
jar1 8 K
jar2 1 S
jar2 2 A
jar2 3 K
jar2 4 L
jar2 5 A
jar2 6 K
jar2 7 S
jar2 10 K

$ paste B file2 |awk '{print $1,$2,$NF}' > C
$ cat C
jar1 1 0.2
jar1 2 0.4
jar1 3 0.2
jar1 4 0.1
jar1 7 0.3
jar1 8 0.2
jar2 1 2
jar2 2 2
jar2 3 1
jar2 4 7
jar2 5 0.4
jar2 6 0.2
jar2 7 0.5
jar2 10 0.7

$ cat C A |sort 
jar1 1 0.2
jar1 2 0.4
jar1 3 0.2
jar1 4 0.1
jar1 5 0
jar1 6 0
jar1 7 0.3
jar1 8 0.2
jar2 1 2
jar2 10 0.7
jar2 11 0
jar2 2 2
jar2 3 1
jar2 4 7
jar2 5 0.4
jar2 6 0.2
jar2 7 0.5
jar2 8 0
jar2 9 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in sorting the file and putting to a different folder

Hi, I am new to unix. Kindly help me on this. My requirement is as below: I have a path temp/input , temp/CL and temp/CM I have files in temp/input as below (dates in YYYYMMDDHHMISS) NMP1515O.CL.20181026111213 NMP1515O.CM.20181025111213 ... (4 Replies)
Discussion started by: Shanmugapriya D
4 Replies

2. UNIX for Dummies Questions & Answers

Putting file name inside file

I have a bunch of files with unique names. Inside each file are either 1 or more than 1 rows. I would like the name of the file to appear inside the file itself, once per row (except for the first row which is a header). For example: ls dog.1 cat.1 goat.1 tree.1 cat dog.1 ... (4 Replies)
Discussion started by: verse123
4 Replies

3. Shell Programming and Scripting

Taking part of one file name and putting it into a another file name

Not sure how to do the following, but any help would be appreciated. Has to be done using C shell (sorry about that). I have about 300 files that I need this done for, but I am only going to give one example. I will just need to know how to execute your solution through some type of loop to... (2 Replies)
Discussion started by: jclanc8
2 Replies

4. Shell Programming and Scripting

Putting together all values from different files in one file

Hi All, This is what I am trying to achieve but to no avail. I have three sets of files which are: 1. One big dictionary file which looks like this: apple orange computer pear country 2. Some thousands of text files which are named as 1.dat, 2.dat, 3.dat etc The text files... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

5. UNIX for Dummies Questions & Answers

Putting echoed text into a new file

Hi, I've set up a script so that a user answers questions, and then these answers come back onto the screen accompanied by text that I've echoed. Is there a way of putting this into a new file? Thanks (7 Replies)
Discussion started by: likelylad
7 Replies

6. Shell Programming and Scripting

Read data from one file and putting in new file ??

Hello All, I have a file which contain data something like this: CELL 2 TEST AND DIAGNOSTIC UNIT 2 CELL 2, CDM 1 CBR 1 TRANSMIT PORT (TXPORT) 1 CELL 2, CDM 1 CBR 2 TRANSMIT PORT (TXPORT) 1 CELL 2, CDM 1 CBR 3 TRANSMIT PORT (TXPORT) 1 CELL 2, CDM 1 CBR 1 TRANSMIT PORT... (21 Replies)
Discussion started by: wakhan
21 Replies

7. Shell Programming and Scripting

Separating values from a file and putting to a variable

I am writing into a file testfile.txt values like ./XXXXXXCZ1/tprcm10c.bin ./XXXXXXCZ1_HOT/tprcm09c.bin ./XXXXXXCZ_cold/tprcm05c.bin I want to store the values of tprcm*.bin and XXXXXXCZ* in separate variables Can anybody Pls hlp me out with this ... Thanks (2 Replies)
Discussion started by: ultimatix
2 Replies

8. Shell Programming and Scripting

Putting screen output in a log file

I want to output screen messages to a logfile when executing an automated script. I have tried the script and command to do this but with no luck. Thanks, Nicole (5 Replies)
Discussion started by: nsutti
5 Replies

9. UNIX for Dummies Questions & Answers

putting a timestamp in a file

I was sure there was a way to put a timestamp ina logfile but I can't seem to figure out how. What I would like to do is after the last messages in the rptmgr.err log is put a timestamp so I know the next time I look whats new. I am using AIX 5.1 any help will great Thanks (2 Replies)
Discussion started by: rocker40
2 Replies

10. UNIX for Dummies Questions & Answers

putting restrictions when copying file

I would like to create a command to copy a file with a restriction- if the file exists at the copy destination, the copy does not occur and message is provided that file already exists. (3 Replies)
Discussion started by: thoffpauir
3 Replies
Login or Register to Ask a Question