Here's the output of a grep command I ran:[user@localhost] : ~/Documents/challenge $ grep -i -e .\{32\} fileA fileBfileA:W0mMhUcRRnG8dcghE4qvk3JA9lGt8nDlfileB:observacion = new Observacion();fileB:observacion.setCodigoOf(ordenBO.getCodigo());fileB:observacion.setDetalle(of.getObservacion().getSolicitante());fileB:observacion.setTipoObservacion(TipoObservacionOrdenFleteMaestro.SOLICITANTE);fileB:observacion.setProceso(TipoProcesoObservacionMaestro.MODIFICACION);fileB:observacion.setFecha(Utiles.getFechaSistema());fileB:java.util.Date fechaHora = Calendar.getInstance().getTime();fileB:observacion.setUsuarioCrecion(usuarioSesionado.getUsuario().getUsuario());fileB:daoObservacion.agregaObservacion(observacion);I'm looking for 32 character long string in two files: fileA and fileB. Importantly, fileA contains exactly 32 characters only, with no line breaks:[user@localhost] : ~/Documents/challenge $ hexdump -C fileA00000000  57 30 6d 4d 68 55 63 52  52 6e 47 38 64 63 67 68  |W0mMhUcRRnG8dcgh|00000010  45 34 71 76 6b 33 4a 41  39 6c 47 74 38 6e 44 6c  |E4qvk3JA9lGt8nDl|00000020The problem with my grep command is that it is returning any line that has more than 32 chars. How can I make it return only lines with exactly 32 chars. The issue for me is that I can't modify my regex to match on a line break, because there is no line break.My expected output would be simply:fileA:W0mMhUcRRnG8dcghE4qvk3JA9lGt8nDl(note: this is for a challenge that I've already solved with my ugly solution, but in this scenario we can only use grep and piping or redirecting output is not allowed)
grep for lines/files that contain exactly X chars
terminal;grep;regular expression
This works.  ^ denotes start of line, plus the {32} you already had, then a $ for end of line.$ cat fileA fileB1234567890123456789012345678901212345678901234567890123456789012312345678901234567890123456789012123456789012345678901234567890124$ grep -E ^.{32}$ fileA fileBfileA:12345678901234567890123456789012fileB:12345678901234567890123456789012$And as pointed out by @steeldriver, posix grep includes -x, so the following approach also works : grep -xE .{32} fileA fileB