How to analyze file contents using sed / awk?

My input file has its content in the following format, where each column is separated by a space

string1<space>string2<space>string3<space>YYYY-mm-dd<space>hh:mm:ss.SSS<space>string4<space>10:1234567890<space>0e:Apple 1.2.3.4<space><space>string5<space>HEX  

After "0e: Apple 1.2.3.4" there are 2 "spaces", because there is no 14th digit in this field / column. The entire "0e: Apple 1.2.3.4space" is considered as one value of this column.

In the 7th column 10: displays the number of characters in the next row.

In the eighth column, 0e: represents the hexadecimal value of 14. Thus, the HEX values ​​indicate the number of characters in the next row.

Like:

"0e:Apple 1.2.3.4 "--> this is the actual value in 8th column without " "  
    (I've mentioned " " to show that the 14th digit is empty)  

It counted as  
0e:A p p l e   1 . 2 .   3  . 4    
   | | | | | | | | | |   |  | | |  
   1 2 3 4 5 6 7 8 9 10 11 12 1314  

Consider the first line from the input file as:

string1 string2 string3 yyyy-mm-dd 23:50:45.999 string4 10:1234567890 0e:Apple 1.2.3.4  string5 001e  

Where:

  • string1 - value in the 1st column
  • string2 - value in the second column
  • string3 - value in the third column
  • yyyy-mm-dd in the 4th
  • 23:50:50.999 in the 5th
  • string3 in the 6th
  • 10:1234567890 7-// , 10
  • 0e:Apple 1.2.3.4 //
  • string5 9-
  • 001e 10-

:

string1,string2,string3,yyyy-mm dd,23:50:50.999,string3,1234567890,Apple_1.2.3.4,string5,30  

:

  • 7- 8- (10: 0e:)
  • b/w Apple 1.2.3.4 "_"
  • .
  • "" , "
  • 10- . , ? ?

:

$ cat input.txt |sed 's/[a-z0-9].*://g'  

:

string1,string2,string3,yyyy-mm-dd,45.999,string4,1234567890,Apple,1.2.3.4,,string5,001e  
+4
1

, :

awk -F "[ ]" '{sub(/.*:/, "", $7) sub(/.*:/, "", $8); printf "%s,%s,%s,%s,%s,%s,%s,%s_%s,%s,%s,%d\n", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, "0x"$12}' input.txt

:

awk printf , , , _.

-F "[ ]" , , . , , , .

sub , ..: 7 8.

12 printf ( %d) 0x, .

. , $8_$9, , , . , - , . Python.

+2

All Articles