-1

Hello a file I am working with looks:

   header
//
SeqT: {"POS-s":174.683, "time":0.0130084}
SeqT: {"POS-s":431.49, "time":0.0221447}
[2.04545e+2]:0.00843832,469:0.0109533):0.00657864,((((872:0.00120503,((980:0.0001);
[29]:((962:0.000580339,930:0.000580339):0.00543993);
absolute:
gthcont: 5 4 2 1 3 4 543 5  67 657  78 67 8  5645 6 
01010010101010101010101010101011111100011
1111010010010101010101010111101000100000
00000000000000011001100101010010101011111

Using thsi code from awk

    !body && /^\/\/$/              {body=1}
body  && sub(/^gthcont: */,"") {print > "second_"FILENAME}
body  && /^[01]+/              {print > "third_"FILENAME}
body  && /^\[[0-9]+\]/ {
    print > "first_"FILENAME
    print substr($0, 2, index($0,"]")-2) > "fourth_"FILENAME
}
sub(/^SeqT: {"POS-s":/,"") && sub(/, "time":/," ") && sub(/}$/,"") { print >"fifth_"FILENAME}

I need it to be split into five files. The first file is

[2.04545e+2]:0.00843832,469:0.0109533):0.00657864,((((872:0.00120503,((980:0.0001);
[29]:((962:0.000580339,930:0.000580339):0.00543993);

The second file has to be

5 4 2 1 3 4 543 5  67 657  78 67 8  5645 6

The next file has to be

01010010101010101010101010101011111100011
11110100100101010101010101111010001000001
00000000000000011001100101010010101011111

the fourth file should have the numbers from within the brackets in the first file..in this case it woudl only be

2.04545e+2
29

and the last file

174.683 0.00130084
431.49 0.0221447 

The code works but the problem is that it has problems with using the sci notation (e+7 and something like this ).In this line there is no print out in the file just containing the numbers from the []. So currently the file does not look like 2.04545e+2 29 but onl y

29..

how can i adjust the awk to also read in sci notation in the []?

0

You need to replace the regular expression /^\[[0-9]+\]/, which only matches one or more digits within square brackets, with a regex that matches your floating-point input.

For example, taking the expression

[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?

for a floating-point number with exponent from Jan Goyvaerts' Matching Floating Point Numbers with a Regular Expression tutorial and substituting it in your awk code:

awk 'BEGIN{body=0}
!body && /^\/\/$/    {body=1}
body  && /^\[/       {print > "first_"FILENAME}
body  && /^pos/{$1="";print > "second_"FILENAME}
body  && /^[01]+/    {print > "third_"FILENAME}
body  && /^\[[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\]/ {
  print > "first_"FILENAME
  print substr($0, 2, index($0,"]")-2) > "fourth_"FILENAME
}' file

with your example input in file, you should now get

$ cat fourth_file 
2.04545e+2
29
  • just noticed that there was a prob in the coee could you mayeb u the answer absed on the new awk cod? – kagh Jul 26 '15 at 15:22
  • @kagh I'm not sure what you're asking for: the relevent part of your awk script (i.e. the regex for the fourth element) appears to be unchanged in the modified version. Why do you need an updated answer? Did you try modifying the regex as I described? – steeldriver Jul 26 '15 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.