regex - How do I split an integer using an "if" condition? -
i've been looking days trying use awk, sed, cut, , tr possible solution problem. have data set thats delimited "@" shown below...
1@2@11@11/8@11/8@11@11/2 2@4@31 1/2@31 1/2@31/2@21@21/2 3@10@116 1/4@98@911 3/4@410@38 1/2 4@1@21@21/8@21/8@33@49 1/4 5@11@74@75@67 1/2@511 1/2@511 1/2 6@9@106@108 1/4@89 1/4@613 1/2@616 7@7@96@118 1/4@1313 1/2@715@717 3/4 8@12@127 3/4@129 3/4@1212 1/2@816 1/2@817 3/4 9@6@63@ 64 1/2@79@916 1/2@918 10@13@139 3/4@1311 1/4@1112@1017@1019 3/4 11@3@42@42@43 1/2@1118 1/2@1126 1/4 12@5@84 1/2@87@1011 3/4@1219 1/2@1228 1/4 13@8@52 1/2@53 1/2@57@1324@1332 3/4
what split row numbers in first column (the ranks) rest of integers in other columns starting @ column 3 , on. end results this...
1@2@1@1@1@1/8@1@1/8@1@1@1@1/2 2@4@3@1 1/2@3@1 1/2@3@1/2@2@1@2@1/2 3@10@11@6 1/4@9@8@9@11 3/4@4@10@3@8 1/2 4@1@2@1@2@1/8@2@1/8@3@3@4@9 1/4 5@11@7@4@7@5@6@7 1/2@5@11 1/2@5@11 1/2 6@9@10@6@10@8 1/4@8@9 1/4@6@13 1/2@6@16 7@7@9@6@11@8 1/4@13@13 1/2@7@15@7@17 3/4 8@12@12@7 3/4@12@9 3/4@12@12 1/2@8@16 1/2@8@17 3/4 9@6@6@3@6@4 1/2@7@9@9@16 1/2@9@18 10@13@13@9 3/4@13@11 1/4@11@12@10@17@10@19 3/4 11@3@4@2@4@2@4@3 1/2@11@18 1/2@11@26 1/4 12@5@8@4 1/2@8@7@10@11 3/4@12@19 1/2@12@28 1/4 13@8@5@2 1/2@5@3 1/2@5@7@13@24@13@32 3/4
i thinking use "if statement". "if integers start [2-9] split after 1 character, elif starts [1] , length equal 3 or more (before space , fraction) split firsts 2 characters." have no idea how how go solving problem. have thousands of similar files , need change structure of them, solution have ran through loop.
here's fun one:
perl -f@ -lape '$_ = join "@", shift(@f), shift(@f), map {s/(1\d|\d)(\d+)/$1\@$2/g; $_} @f' file
with little commentary
perl -f@ -lape ' $_ = join "@", # join following things, using "@" shift(@f), # first field shift(@f), # second field map { # then, transform rest expr s{ # search for: (1\d | \d) # 1 plus digit, or digit (\d+) # followed 1 or more digits }{$1\@$2}xg; # add "@" in between $_ # , return new string } @f ' file
the options:
-a
,-f@
-- split each line array@f
using@
character separator-l
-- handle line endings automatically-p
-- automatically print variable$_
after processing each line
Comments
Post a Comment