script to replace numbers on lines according to condition on the same line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to replace numbers on lines according to condition on the same line
# 1  
Old 01-09-2011
script to replace numbers on lines according to condition on the same line

hello everyone

my file contains many records, the following is a sample:
Code:
BEGIN
ASX1500000050002010120000000308450201012000177
ASX1100002000000201012000000038450201012000220
ASX1600100005000201012000000038450020101200177
ASX1900100006000201067000000058450020101200177
ASX1100002000000201012300000008450201012000177
ASX1100002000000201012380000000450201012000277
ASX1800100004000201012380000000452010120000177
ASX1100002000000201012380000000450201012000177
ASX1900100006000201067500000008450201012000120
ASX1100005000000201012380000000450201012000377
ASX1100002000000201012380000000450201012000177
ASX1100002000000201012384000000052010120000477
ASX1900100006000201067584000000050201012000177
ASX1900100006000201067584500000000201012000177
ASX1100003000000201012384500000000002010120377
ASX1100003000000201012380000000450201012000177
END

what i need is to:
for each line:
1- search for 13 digits number after ASX and that number starts with 11 and contains 2 at digit 7 of this number
2- after finding this number, search in the same line for the blue three digits
if they = 001 or 002
3- if step 1 and 2 is true (lines with red and blue numbers meet this requirement) then:
replace the digits 7 to 0

the output should be
Code:
ASX1500000050002010120000000308450201012000177
ASX1100000000000201012000000038450201012000220
ASX1600100005000201012000000038450020101200177
ASX1900100006000201067000000058450020101200177
ASX1100000000000201012300000008450201012000177
ASX1100000000000201012380000000450201012000277
ASX1800100004000201012380000000452010120000177
ASX1100000000000201012380000000450201012000177
ASX1900100006000201067500000008450201012000120
ASX1100005000000201012380000000450201012000377
ASX1100000000000201012380000000450201012000177
ASX1100002000000201012384000000052010120000477
ASX1900100006000201067584000000050201012000177
ASX1900100006000201067584500000000201012000177
ASX1100003000000201012384500000000002010120377
ASX1100003000000201012380000000450201012000177
BEGIN
 
END

how to do it?
thank you
# 2  
Old 01-09-2011
Code:
awk '$4==1 && $5==1 && $10==2 && $42==0 && $43==0 && ($44==1 || $44==2) {$10=0}1' FS= OFS= infile

Code:
sed '/^ASX11....2.\{31\}00[12]/s/./0/10' infile


Last edited by Scrutinizer; 01-09-2011 at 08:09 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 01-09-2011
Thank you Scrutinizer
sed works great
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script using awk to find and replace a line, how to ignore comment lines

Hello, I have some code that works more or less. This is called by a make file to adjust some hard-coded definitions in the src code. The script generated some values by looking at some of the src files and then writes those values to specific locations in other files. The awk code is used to... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

2. UNIX for Dummies Questions & Answers

How can I replace the lines that start with a star and replace it with numbers start from 1?

I need to replace the (*) in the fist of a list with numbers using sed for example > this file contain a list * linux * computers * labs * questions to >>>> this file contain a list 1. linux 2. computers 3. labs 4. questions (7 Replies)
Discussion started by: aalbazie
7 Replies

3. Shell Programming and Scripting

Shell Script to find common lines and replace next line

I want to find common line in two files and replace the next line of first file with the next line of second file. (sed,awk,perl,bash any solution is welcomed ) Case Ignored. Multiple Occurrence of same line. File 1: hgacdavd sndm,ACNMSDC msgid "Rome" msgstr "" kgcksdcgfkdsb... (4 Replies)
Discussion started by: madira
4 Replies

4. UNIX for Dummies Questions & Answers

Replace lines of two files by the corresponding line numbers.

I want to replace lines. The files 1 are (separated by \t) Gm01 phytozome9_0 three_prime_UTR 70641 70759 . - . ID=PAC:26323927.three_prime_UTR.1;Parent=PAC:26323927;pacid=26323927 Gm01 phytozome9_0 three_prime_UTR 90230 90692 . - . ... (1 Reply)
Discussion started by: grace_shen
1 Replies

5. Shell Programming and Scripting

Replace a multi-line strings or numbers

Hi I have no experience in Unix so any help would be appreciated I have the flowing text 235543 123 45654 199 225 578 45654 199 225 I need to find this sequence from A file 45654 199 225 (22 Replies)
Discussion started by: khaled79
22 Replies

6. Shell Programming and Scripting

Need to delete all lines where any line meets a condition

Here is an example of a file... foo1,good foo1,good foo2,error foo2,good Note that both rows for foo1 have good in the 2nd field, but one of the foo2 rows has error... I need something in ksh/awk/perl that will delete ALL foo2 lines if ANY of them have error in the 2nd field...so: ... (7 Replies)
Discussion started by: dbiggied
7 Replies

7. Shell Programming and Scripting

sed&awk: replace lines with counting numbers

Dear board, (I am trying to post this the 3rd time, seems there's some conflicts with my firefox with this forum, now use IE) ------ yes, I have searched the forum, but seems my ? is too complicated. ------------origianl file --------------- \storage\qweq\ertert\ertert\3452\&234\test.rec... (4 Replies)
Discussion started by: oUo
4 Replies

8. Emergency UNIX and Linux Support

Find a line using a condition and replace a string in that line

Hello, I have a 100 line code. I have given a sample of it below: ABC*654654*1*54.54*21.2*87*1*654654654654 CCC*FS*FS*SFD*DSF GGG*FGH*CGB*FBDFG*FGDG ABC*654654*1*57.84*45.4*88*2*6546546545 CCC*WSF*SG*FGH*GHJ ADA*AF*SFG*DFGH*FGH*FGTH I need to select the line starting with "ABC" its... (3 Replies)
Discussion started by: nithins007
3 Replies

9. Shell Programming and Scripting

Find a line using a condition and replace a string in that line

Hello, I have a 100 line code. I have given a sample of it below: ABC*654654*1*54.54*21.2*87*1*654654654654 CCC*FS*FS*SFD*DSF GGG*FGH*CGB*FBDFG*FGDG ABC*654654*1*57.84*45.4*88*2*6546546545 CCC*WSF*SG*FGH*GHJ ADA*AF*SFG*DFGH*FGH*FGTH I need to select the line starting with "ABC" its... (6 Replies)
Discussion started by: nithins007
6 Replies

10. Shell Programming and Scripting

concatenate and display 2 lines as 1 with a condition for 2 line ?

I have 2 pattern of lines (SQL query and Time taken)in a log i need to capture all SQL queries with time taken >20 sec and need to display as one line. 2 lines from log: 2007-10-23 11:39:17,061 DEBUG - SQL Query : SELECT A.GROUP_CD , C.FN_CD FROM UP_GROUP A , PRD_GROUP_TO_FN B , PRD_FN... (7 Replies)
Discussion started by: vithala
7 Replies
Login or Register to Ask a Question