Кажется, это работает. Я не уверен, есть ли более простой способ сделать это:
grep OpenFin LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'\r' >> LoginExcInternal.txt &&
grep Chrome LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'\r' >> LoginExcInternal.txt &&
grep MemoryUnderThreshold.txt memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt
Предположим, вы сохранили этот AWK-скрипт какscript
:
BEGIN {
# Populate an array that lists (is indexed
# by) the position of "dynamic" fields.
split(dynamic,temp,",")
for (i in temp)
tosplit[temp[i]] = i
}
{
# Determine how many times the current
# line will be repeated...
times = 1
# by counting how many times, for each field,
for (f = 1; f <= NF; f++) {
# the "|" separator is replaced by itself.
repl = gsub(/\|/, "&", $f)
if ( (repl + 1 ) > times)
times = (repl + 1 )
}
# For each time the line has to be repeated:
for (i = 1; i <= times; i++) {
for (f = 1; f <= NF; f++) {
# every "dynamic" field is split on "|", and
# only the component which belongs to the
# current line repetition is printed;
if (f in tosplit) {
split($f, p, "|")
printf( (f == NF ? "%s"ORS : "%s"OFS), p[i] )
}
# all other fields are printed unchanged.
else
printf( (f == NF ? "%s"ORS : "%s"OFS), $f )
}
}
}
вы можете вызвать его как:
awk -v FS=',' -v OFS=',' -v dynamic=3,4,5 -f script source_file
Индексы столбцов, подлежащих разбиению, ("динамические" поля )передаются в awk
как переменная, содержащая список, -разделенный запятыми.