Hello,
I'm new to Sheel script and I need your help for a script I need to develop (for me).
Indead, I have a software which log all entry from internet and save it in text file.
But, the log is practically unreadable because every 256 characters jump to a new line (even if the message is not finish).
For example (fake):
I need to transform it into:
I tried some script with uniq or sort, but, I'm beginner and I need your help
Thanks a lot for your response,
Acid
[edit] the log file can be huge (100 000 lines, so it's vey unpleasant to read)
Try out this code...
origfile.txt= The actual log file
newfile.txt = formatted log file created by script.
cat origfile.txt|cut -c 1-20|while read line
do
log=`grep -i "${line}" origfile.txt|cut -c 24- |sed 's/"//g'`
grep -i "${line}" newfile.txt > /dev/null 2>&1
if [ $? -ne 0 ];then
echo $line:1:$log >> newfile.txt
fi
done
1 Like
See if this works for you:
#!/usr/bin/ksh
while read mLine; do
mTag=$(echo ${mLine} | cut -d':' -f5)
if [[ "${mTag}" = "id_0000" ]]; then
echo ${mLine}
mFirst="Y"
else
if [[ "${mTag}" = "id_0001" ]]; then
if [[ "${mFirst}" = "Y" ]]; then
mOutLine=$(echo ${mLine} | sed 's/"$//')
mFirst="N"
else
mValue=$(echo ${mLine} | sed 's/.*://;s/"//g')
mOutLine=${mOutLine}${mValue}
fi
else
echo ${mOutLine}'"'
echo ${mLine}
fi
fi
done < inp_file
1 Like
Firslty, thank a lot for your help
vipinable, I tried your script, I have no error at all when I launch the script but it's never stop for me ? But I'll try to understand in depth your code
Shell_Life, I guess your script work only for my example? But thanks a lot, I'll try to use you algorithm too
Thanks you again
Acid
[edit] vipinable, sorry, your script work !! thank a lot
$ awk -F\: '{key=substr($0,0,20);gsub(/\"/,"");arr[key]=arr[key]$NF;} END{for (k in arr) printf "%s:\"%s\"\n", k,arr[k]}' file.txt
10:04:56:201:id_0002:"RaZ."
10:02:23:125:id_0001:"A entry was detected at port 200. Please call suport."
10:02:23:124:id_0000:"RaZ."
1 Like
Wow i love your solution Thanks a lot...