Вы можете выполнить задачу с помощью цикла, nl
( n umbering l ine ) и sed
( s tring e ditor)
for f in scenario*.csv
do
#next will numerate all lines exept first (started without number)
nl -bp^[0-9] -nln -w1 "$f" |
sed '
#add the «p» before line number
s/^[0-9]/p&/
#put «pNUM» on the place of second field started with «NUM-NUM»
s/\(^p[0-9]*\)\s*\([0-9]*,\s*\)[0-9]-[0-9][^,]*/\2\1/
#removes spaces from the line begining (may be for header only)
s/^\s*//
' > out.tmp #outputs changed lines into temporary file
mv out.tmp "$f" #move temp file to original
done
rm out.tmp #delete temp file
Буферизация мешает.
Используйте while read line
из оболочки, которая должна читать строку -за строкой -и избежать большинства проблем с буферизацией:
tail -f /var/log/httpd/modsec_audit.log | while read line; do
echo "$line" | sed 's/[^\/]*/\./;s/].*$//g' | awk '{print $0}' | xargs cat
done
Хотя вы, вероятно, можете сделать лучше, используя оболочку (bash ), чтобы также сопоставить имя файла из строки журнала:
tail -f /var/log/httpd/modsec_audit.log | while read line; do
line=${line/*([^\/])/.}
line=${line%]*}
[[ -n "${line}" ]] && cat "${line}"
done
попробуй с этим:
tail -f /var/log/httpd/modsec_audit.log | stdbuf -oL sed 's/[^\/]*/\./;s/].*$//g' | stdbuf -oL awk '{print $0}' | while IFS='' read -r file; do cat $file ; done