I have a file that contains lines of the following format:
w1 # 1 # x w2 # 4 # b w3 # 2 # d ...
Each word (token) in a string (for example, w1 # 1 # x) consists of 3 parts, the first shows an index (w1 in this case), the second an integer (in this case 1) and the third character (x in this case )
Now for each word (token) I need to print an additional field, which will be calculated based on the value of the second and third parts (i.e. the fourth part will be a function of the 2nd and 3rd parts), and the output file should look like this:
w1 # 1 # x # f1 w2 # 4 # b # f2 w3 # 2 # d # f3 ...
Where
f1 = function (1, x), f2 = function (4, b), f3 = function (2, d)
Now, using sed patterns, I can identify the components in each word (token), for example,
echo $line | sed "s/([^ #]) # ([^ #]) # ([^ #] *)/\ 1 #\2 #\3/g"
\2 \3 - ( - )
\2 \3. getInfo(), 2 . sed. :
echo $line | sed "s/([^ #]) # ([^ #]) # ([^ #] *)/\ 1 #\2 #\3`getInfo\2\3`/g"
. Shell .
, :
sed ()?
script, , , , sed sed.
,