0
votes

En utilisant awk pour la déclaration et diviser

J'ai un fichier system.log à ressembler.

[2019-12-20 10:08:04:101,"search":"ea"} [] []
[2019-12-20 10:08:35:101,"search":"ea"} [] []


0 commentaires

6 Réponses :


7
votes

Pourriez-vous essayer de suivre, écrit et testé avec des échantillons montrés dans GNU awk code>. xxx pré>

strong> strong> Ajout d'une explication détaillée pour ci-dessus. P>

awk -v s1="\"" '                                     ##Starting awk program from here and setting s1 as value " here.
/Customer Id:/{                                      ##Searching string Customer Id: in current line here.
  match($0,/\[[0-9]{4}-[0-9]{2}-[0-9]{2}/)           ##Using match function of awk and using regex here for current line to get value of date here.
  dat=substr($0,RSTART+1,RLENGTH-1)                  ##Creating dat variable and having sub string value in it for current line.
  match($0,/Param: {.*}/)                            ##Using match to match regex Param: { till } here.
  val=substr($0,RSTART,RLENGTH)                      ##Creating val which has sub string of previous used match function here.
  gsub(/.*:"|"}$/,"",val)                            ##Globally substituting till :" OR "} in last of val here with NULL.
  print dat,s1 val s1                                ##Printing dat s1 val and s1 here.
  dat=val=""                                         ##Nullifying dat and val here to avoid conflict of variable values here.
}
' Input_file                                         ##Mentioning Input_file name here.


2 commentaires

Très bien expliqué réponse ++


Vous faites du bon travail pour expliquer vos commandes. Aide beaucoup quand quelqu'un est hors de contact ou nouveau.



1
votes

Vous pouvez utiliser ce gnu awk avec FPAT : xxx xxx


0 commentaires

3
votes

Simplement simple: xxx

sortie: xxx

expliqué:

si l'antépénultième space séparé String a une sous-chaîne "..."} , Imprimer la première chaîne séparée de l'espace à partir du deuxième caractère (à l'exclusion du premier caractère [ ) et la sous-chaîne susmentionnée excluant le dernier caractère } .


0 commentaires

0
votes

avec sed xxx

  • -n désactive l'impression automatique
  • -E Activer ERE
  • ^ \ [ correspond au démarrage [
  • ([^] +) capture la date
  • . * "Recherche": correspondance jusqu'à "Recherche":
  • ("[^"] + ") capture la valeur de la recherche
  • . * reste de la ligne
  • \ 1 \ 2 Le texte correspondant par les groupes de capture séparés par l'espace
  • p Imprimez uniquement si la substitution réussit

0 commentaires


0
votes

Je pense que je peux le simplifier à xxx


0 commentaires