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

304
Views
Reemplace una línea que comience con un guión '-' con un carácter repetido n veces

Tengo un archivo de texto que tiene algunas líneas como esta (guion repetido)

 -------------------------------------------------------

Necesito reemplazar estas líneas con el carácter 'B' repetido 1500 veces. por ejemplo, como

BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

¿Alguna sugerencia para usar el comando 'sed' o 'awk'?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Con awk :

 $ awk '/^-+$/ {s = sprintf("% 1500s", ""); gsub(/ /,"B",s); print s; next} 1' file

O, tal vez un poco más eficiente si tiene muchas líneas de este tipo:

 $ awk 'BEGIN {s = sprintf("% 1500s", ""); gsub(/ /,"B",s)} \ /^-+$/ {print s; next} 1' file
over 4 years ago · Santiago Trujillo Report

0

pienso

 perl -pe 'my $bb = "B"x1500; s/^-+$/$bb/g'

Deberías hacerlo.

over 4 years ago · Santiago Trujillo Report

0

variante printf+sed:

 $ cat file 1111 ---- 2222 $ sed -r 's/^-+$/'"$(printf -- "%.1s" B{1..150})/" file 1111 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 2222

Aquí sed se usa solo para reemplazo.
printf se usa para generar 1500 veces B. (El scriptlet anterior tiene 150 en lugar de 1500, porque requiere demasiado desplazamiento).

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!