Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
Bash & awk: falla de segmentación al intentar usar el argumento del script bash en awk

Estoy tratando de escribir un script para extraer registros entre dos marcas de tiempo usando awk.

Así que esto funciona:

 awk '$0 >= "07-Nov-2021 13:40:02.124" && $0 <= "07-Nov-2021 13:43:08.124"' websniffer.log

Pero cuando lo uso dentro de un script bash, estoy luchando para que funcione. Aquí está mi secuencia de comandos y error de muestra mínimos:

 #!/bin/bash fromtime=$1 totime=$2 nameoffile="websniffer.log" awk -v fromtimestamp=$fromtime -v totimestamp=$totime -v filenm=$nameoffile '$0 >= "$fromtimestamp" && $0 <= "$totimestamp"}' $filenm

Ahora, cuando ejecuto este script por:

 #terminal@root$ ./samplescript.sh "07-Nov-2021 13:40:02.124" "07-Nov-2021 13:43:08.124"

Entiendo esto :

 ./samplescript.sh "07-Nov-2021 13:40:02.124" "07-Nov-2021 13:43:08.124"./samplescript.sh "07-Nov-2021 13:40:02.124" "07-Nov-2021 13:43:08.124" ./samplescript.sh: line 6: 2190 Segmentation fault awk -v fromtimestamp=$fromtime -v totimestamp=$totime -v filenm=$nameoffile '$0 >= "$fromtimestamp" && $0 <= "$totimestamp"}' $filenm

¿Puede alguien ayudarme a hacer que esto funcione?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Hay un par de cosas:

 #!/bin/bash fromtime=$1 totime=$2 nameoffile="websniffer.log" awk -v fromtimestamp="$fromtime" -v totimestamp="$totime" '$0 >= fromtimestamp && $0 <= totimestamp' "$nameoffile"

Debe citar las variables de shell que pasa a awk (tienen espacios en blanco) y no es necesario crear filenm y pasarlo a awk ya que no lo está usando dentro del script awk.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!