Execution Problems with scan and change file data content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution Problems with scan and change file data content
# 1  
Old 10-12-2010
Execution Problems with scan and change file data content

Input file
Code:
>Read_1
XXXXXXXXXXSDFXXXXXDS
ASDRXXXXXTGAGTXXXXXT
TGTGATXXXXXAXXXXGXXA
.
.

Desired output file
Code:
>Read_1
XXXXXXXXXXXXXXXXXXDS
ASDRXXXXXTGAGTXXXXXT
TGTGATXXXXXXXXXXXXXA
.
.

Once I scan the last "X" and next coming "X" 's distance is less than or equal to 3 letters, I will replace those letter between the last "X" and next coming "X" with "X"
Thanks for any advice.
# 2  
Old 10-12-2010
Code:
 perl -pe 's/X[^X]X/XXX/g;s/X[^X]{2}X/XXXX/g;s/X[^X]{3}X/XXXXX/g;' input


Last edited by bartus11; 10-12-2010 at 02:07 PM..
This User Gave Thanks to bartus11 For This Post:
# 3  
Old 10-12-2010
sed 's/X[^X]X/XXX/g;s/X[^X][^X]X/XXXX/g;s/X[^X][^X][^X]X/XXXXX/g' input >output
This User Gave Thanks to ctsgnb For This Post:
# 4  
Old 10-14-2010
Hi bartus11,
Thanks for your perl command.
Do you have any idea if my input data is shown as below:
Code:
>Read_1
XXXXXXXXXXSDFXXXXXDS  (condition 1: After the last "X" per line, if the distance is less than or equal to 3 letter, replace those not "X" letter with "X")
TREXXXXXXXSDFXXXXXDS (condition 2: Before the first "X" per line, if the distance is less than or equal to 3 letter, replace those not "X" letter with "X")
.
.

Desired output:
Code:
>Read_1
XXXXXXXXXXSDFXXXXXDS
XXXXXXXXXXSDFXXXXXDS
.
.

Do you have any suggestion if facing the above situation?
I got try using this one for condition 1. But it is not worked:
Code:
perl -pe 's/X[^X]{2}$/XXX/g' input

Thanks for any advice.
# 5  
Old 10-16-2010
Code:
sed 's/X[^X][^X][^X]$/XXXX/;s/X[^X][^X]$/XXX/;s/X[^X]$/XX/;s/^[^X][^X][^X]X/XXXX/;s/^[^X][^X]X/XXX/;s/^[^X]X/XX/' input > output


Last edited by Scott; 10-16-2010 at 09:36 PM.. Reason: Code tags
# 6  
Old 10-18-2010
Code:
while(<DATA>){
  s/(?<=X)([^X]+)(?=X)/(length($1)>3)?$1:"-" x length($1)/eg;
  print;
}
__DATA__
XXXXXXXXXXSDFXXXXXDS
XXaaXbbXXXXXXXSDFXXXXXDS
ASDRXXXXXTGAGTXXXXXT
TGTGATXXXXXAXXXXGXXA

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to change the file content using some conditions

Hello, I would like to change the content of the file that has few blocks starts with 10 and ends with ";" File1.txt 10 bonuses D 20 MATCHED 30 UPD COL 40 (SOL=30) 20 NOT MATCHED 30 INS COL 40 (SOL=30) ; 10 bonuses D 20 MATCHED 30 UPD COL 40... (5 Replies)
Discussion started by: Mannu2525
5 Replies

2. Shell Programming and Scripting

Change a file content format using awk

Hi, i have a file input.txt Continent North America Country USA Capital Washington D.C. Country Canada Capital Ottawa Continent South America Country Argentina Capital Buenos Aires Country Brazil Capital Brasília Coutry Colombia Capital Bogotá and i want to get an output.txt ... (3 Replies)
Discussion started by: fastlane3000
3 Replies

3. Shell Programming and Scripting

Execution Problem with dispalying file content using menu driven script

HI All.. below is my menu options script. in option 2,3 and 4 im giving input and they are saving into their respective text file. problem is when im trying to "cat" those files in options 7,8 and 9 im not getting the output. no respective file contents are displaying on screen. but if i... (1 Reply)
Discussion started by: saichand1985
1 Replies

4. Linux

when SCP, does file content change?

Good day to you all, Just want to check here, i know when scping a file, size might change due to space issue. it might sound silly, but does file content get change too? if so, what kind of situation that might be? (1 Reply)
Discussion started by: ahtat99
1 Replies

5. Shell Programming and Scripting

Scan and change file data content problem

Input file >Read_1 XXXXXXXXXXSDFXXXXXDS (condition 1: After the last "X" per line, if the distance is less than or equal to 3 letter, replace those not "X" letter with "X") TREXXXXXXXSDFXXXXXDS (condition 2: Before the first "X" per line, if the distance is less than or equal to 3 letter,... (12 Replies)
Discussion started by: patrick87
12 Replies

6. Shell Programming and Scripting

Excution Problems with loading huge data content and convert it

Hi, I got long list of referred file content: CGTGCFTGCGTFREDG PEOGDKGJDGKLJGKL DFGDSFIODUFIODSUF FSDOFJSODIFJSIODFJ DSFSDFDFSDOFJFOSF SDFOSDJFOJFPPIPIOP . . . Input file content: >sample_1 SDFDSKLFKDSLSDFSDFDFGDSFIODUFIODSUFSDDSFDSSDFDSFAS (14 Replies)
Discussion started by: patrick87
14 Replies

7. Shell Programming and Scripting

Execution problems when added two same content in each line

Input: >sample_1 ASDAFDGSGH >sample_2 ASDFDAFDSFS >sample_3 ASDAFDAFDFD >sample_4 ASDFDFDSFDSF . Desired output >sample_1 ASDAFDGSGHXX >sample_2 ASDFDAFDSFSXX >sample_3 ASDAFDAFDFDXX (2 Replies)
Discussion started by: patrick87
2 Replies

8. Shell Programming and Scripting

Change file content based on data

I have a Transaction File coming into the system. In this file, in all records the relevant data is as follows- Position 1:10 -> Transaction Code Position 252:255 -> 4 digit business code Now based on these 2 fields I have to alter value in Transaction code (Position 1:10)... (6 Replies)
Discussion started by: varunrbs
6 Replies

9. Shell Programming and Scripting

How to change a file's content by row?

Greetings. So the question is basically the same as it's in the title. I'd like to write a program that changes a file by rows. So to clarify it. (i know i shouldn't use code,/code here but i would like to separate it) So for example a text file looks like something like this: Happy... (5 Replies)
Discussion started by: buddhist
5 Replies

10. Shell Programming and Scripting

Need help to change the content for remote located file

Hi All, I have a file that sits on 4 diffrent servers, those servers are diffrent region based and they are authentication protected and that file has a diff port numbers, so when run the script it must ask my login details,region of server and port no for that file once it took from me it... (1 Reply)
Discussion started by: tmarjuna
1 Replies
Login or Register to Ask a Question