Не уверен, что правильно понял ваш запрос, но как насчет
awk -F"\t" '
NR > 1 {i = 2
while (i<=NF) {if (!$i) {while (!$(++i)) ;
for (j=LAST+1; j<i; j++) $j = ($LAST == $i)?$LAST:"X"
}
LAST = i++
}
}
1
' OFS="\t" file
ID s577 s592 s598 s600 s612 s650 s700 s822 s825 s830 s840 s870
line0 A A A A A A A A A A A A
line1 B B B B X X X X NA X X B
line2 B X X A A A A A A A A A
Аннотированная версия по запросу:
awk -F"\t" '
NR > 1 {i = 2 # Don't work on the header line
while (i<=NF) {if (!$i) {while (!$(++i)) ; # check every field if empty and
# increment i while seeing empty
# fields; i now holds next non-
# empty field
for (j=LAST+1; j<i; j++) $j = ($LAST == $i)?$LAST:"X"
# fill the empty fields with "X"
# or last non-empty field's value
# depending on actual and last
# fields' values being equal or not
}
LAST = i++ # retain last non-empty field
}
}
1 # default action: print
' OFS="\t" file
С помощью GNU вы можете сделать следующееsed
:
$ sed 's:\*\*\([^*]*\)\*\*:<b>\1</b>:g' a.txt
I like reading <b>books</b> and taking <b>notes</b>
Шаблон \*\*\([^*]*\)\*\*
захватывает строку между **...**
, которая не является подстановочным знаком *
. Наконец, вы заменяете захваченную группу на себя между тегами.