Replace dashes positions 351-357 & 024-043 with 0 & replace " " if exis with 04 at position 381-382


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace dashes positions 351-357 & 024-043 with 0 & replace " " if exis with 04 at position 381-382
# 8  
Old 10-01-2012
Is that ONE record that you present in four lines in post #1? Line 1 and 3 have 110 chars, line 2 and 4 have 113 char, totalling to 446 char, not 413 nor 421. Are the lines <lf> terminated/separated, and do you count the <lf> chars (=449 in total)? There's no dashes in pos 351 to 357 (which would be line 4 pos 18 - 24), even if you'd count the <lf>s. One dash in line 1 pos 27 could be replaced, but that's all. There's no two blanks in your input example that could be replaced either.

Pls. provide a meaningful problem and an adequate input sample as well as desired output.

Last edited by RudiC; 10-01-2012 at 12:35 PM..
# 9  
Old 10-01-2012
The latest tested code :

Code:
awk -F "" '{for(i=1;i<=NF;i++){if((i>=351 && i<=357) || (i>=24 && i <=43)){gsub("-","0",$i);} 
else if(i>=381 && i<=382){gsub("  ","04",$i);}}}1' OFS="" input_file

Smilie
This User Gave Thanks to msabhi For This Post:
# 10  
Old 10-01-2012
Thanks pamu and msabhi for you help on this.
But after executing recommended command the output file is still not giving us the expected results.1) for example position 24 to 436 values were 01234-1234,14321-2345, 12345-3236 & 01234-4237 for record 1,2,3,4. after command these values remain same.
2) Position 351 to 357 values were 0-1234567890, 002345678901, 00-456789012 & 004567890123 for record 1,2,3,4 which never got modified.
3) Position 381-382 values were " ", 02, " ", 01 for record 1,2,3 & 4. Here please ignore "" since in order to specify 2 space i used " " these 2 spaces from two record never got changed after our modifed command execution.

I have attached both input and output file for the reference. Please see the attached.
Thanks a lot for helping me out.
# 11  
Old 10-01-2012
Try this:
Code:
awk     'BEGIN{OFS=FS=""}
         {
          if ($381$382=="  ") {$381="0";$382="4"}
          for (i= 24; i<= 43; i++) if ($i=="-") $i="0"
          for (i=351; i<=357; i++) if ($i=="-") $i="0"
         }1
        ' InputFile.dat

---------- Post updated at 05:34 PM ---------- Previous update was at 05:28 PM ----------

Quote:
Originally Posted by lancesunny
I have attached both input and output file for the reference. Please see the attached.
Input.dat and Output.dat are identical.
Code:
$ diff InputFile.dat Output.dat 
$

This User Gave Thanks to RudiC For This Post:
# 12  
Old 10-01-2012
Thank you all for you help on this. Thanks for your time on this.
Thanks a lot RudiC and msabhi.
The code given by RudiC worked like Charm and expected.
Thank you so much for your help on this guys. You guys made my day.
-Lancesunny

Last edited by lancesunny; 10-01-2012 at 12:57 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace multiple "&nbsp;" entry with in <td> tag into single entry using sed?

I have the input file like this. Input file: 12.txt 1) There are one or more than one <tr> tags in same line. 2) Some tr tags may have one <td> or more tna one <td> tags within it. 3) Few <td> tags having "<td> &nbsp; </td>". Few having more than one "&nbsp;" entry in it. <tr> some td... (4 Replies)
Discussion started by: thomasraj87
4 Replies

2. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

3. Shell Programming and Scripting

Remove dashes if exist between positions 351-357 and then add - at the 357th position

I need to remove dash (i.e. -) if present from positions 351-357, and then add - (dash) at 357th position. For example in following first and 3rd record we got Before processing 1) 1st Record positions 351-357 = 0-12345 2) 3rd Record positions 351-357 = 00-4567 After processing:- 1) 1st... (7 Replies)
Discussion started by: lancesunny
7 Replies

4. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

5. UNIX for Dummies Questions & Answers

replace "&quot;" with "&"

I'm trying to replace the string "&quot;" with "&". I have tried this: echo "&quot;" | sed 's/&quot;/&/g' Is it impossible for sed and awk to output "&"? (1 Reply)
Discussion started by: locoroco
1 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

What does this really mean? "tty -s && stty istrip"

I am having hard time understanding what this really do to the environment? I do understand this part "tty -s && stty " but not "istrip" # stty command is executed only if a tty is attached to the process. # stty istrip : Strip input characters to 7 bits tty -s && stty istrip I am... (3 Replies)
Discussion started by: kchinnam
3 Replies

8. Shell Programming and Scripting

Append && echo "success" to all commands

I am learning to build from SVN and other tools, with a lot of copying and pasting from forums. I like to append && echo "success" to all commands so that I can see at a glance if things went all right. Is there a way that I can have the bash shell append this to all commands? Thanks! (5 Replies)
Discussion started by: dotancohen
5 Replies

9. Shell Programming and Scripting

How to replace "\&" with "&"?

I want to remove the backslash in the front of &, and want to use gsub, how to do that? echo "Free \& Long" | awk '{gsub(/\\&/, "&"); print}' This one is not working, and I think it takes the second "&" in gsub as the substitute of "\\&". Thanks a lot! (2 Replies)
Discussion started by: freelong
2 Replies

10. What is on Your Mind?

[[ $(date +%Y) == 2007 ]] && echo "Happy New Year"

Same as the Title! :) (2 Replies)
Discussion started by: ripat
2 Replies
Login or Register to Ask a Question