Skip to main content

tail -n +1 trapetz simpson will print each file with a leading header giving the file name. nl trapetz simpson prints line numbers but no file names. You'll need to use either awk or some shell glue to combine the two.

for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done
for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done

Here's an awk solution which prints the byte count at the bottom:

awk '
    FNR == 1 && NR != 1 {print "end", fn, chars, "characters"; bytes=0}
    END {print "end", fn, chars, "characters"}
    FNR == 1 {print "begin", FILENAME; fn=FILENAME}
    1 {chars += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson
awk '
    FNR == 1 && NR != 1 {print "end", fn, chars, "characters"; bytes=0}
    END {print "end", fn, chars, "characters"}
    FNR == 1 {print "begin", FILENAME; fn=FILENAME}
    1 {chars += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson

tail -n +1 trapetz simpson will print each file with a leading header giving the file name. nl trapetz simpson prints line numbers but no file names. You'll need to use either awk or some shell glue to combine the two.

for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done

Here's an awk solution which prints the byte count at the bottom:

awk '
    FNR == 1 && NR != 1 {print "end", fn, chars, "characters"; bytes=0}
    END {print "end", fn, chars, "characters"}
    FNR == 1 {print "begin", FILENAME; fn=FILENAME}
    1 {chars += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson

tail -n +1 trapetz simpson will print each file with a leading header giving the file name. nl trapetz simpson prints line numbers but no file names. You'll need to use either awk or some shell glue to combine the two.

for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done

Here's an awk solution which prints the byte count at the bottom:

awk '
    FNR == 1 && NR != 1 {print "end", fn, chars, "characters"; bytes=0}
    END {print "end", fn, chars, "characters"}
    FNR == 1 {print "begin", FILENAME; fn=FILENAME}
    1 {chars += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

tail -n +1 trapetz simpson will print each file with a leading header giving the file name. nl trapetz simpson prints line numbers but no file names. You'll need to use either awkawk or some shell glue to combine the two.

for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done

Here's an awk solution which prints the byte count at the bottom:

awk '
    FNR == 1 && NR != 1 {print "end", fn, chars, "characters"; bytes=0}
    END {print "end", fn, chars, "characters"}
    FNR == 1 {print "begin", FILENAME; fn=FILENAME}
    1 {chars += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson

tail -n +1 trapetz simpson will print each file with a leading header giving the file name. nl trapetz simpson prints line numbers but no file names. You'll need to use either awk or some shell glue to combine the two.

for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done

Here's an awk solution which prints the byte count at the bottom:

awk '
    FNR == 1 && NR != 1 {print "end", fn, chars, "characters"; bytes=0}
    END {print "end", fn, chars, "characters"}
    FNR == 1 {print "begin", FILENAME; fn=FILENAME}
    1 {chars += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson

tail -n +1 trapetz simpson will print each file with a leading header giving the file name. nl trapetz simpson prints line numbers but no file names. You'll need to use either awk or some shell glue to combine the two.

for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done

Here's an awk solution which prints the byte count at the bottom:

awk '
    FNR == 1 && NR != 1 {print "end", fn, chars, "characters"; bytes=0}
    END {print "end", fn, chars, "characters"}
    FNR == 1 {print "begin", FILENAME; fn=FILENAME}
    1 {chars += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson
print the name of the correct file on the end line; we're counting characters, not bytes (thanks fered)
Source Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k

tail -n +1 trapetz simpson will print each file with a leading header giving the file name. nl trapetz simpson prints line numbers but no file names. You'll need to use either awk or some shell glue to combine the two.

for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done

Here's an awk solution which prints the byte count at the bottom:

awk '
    FNR == 1 && NR != 1 {print "end", FILENAMEfn, byteschars, "bytes";"characters"; bytes=0}
    END {print "end", FILENAMEfn, byteschars, "bytes""characters"}
    FNR == 1 {print "begin", FILENAMEFILENAME; fn=FILENAME}
    1 {byteschars += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson

tail -n +1 trapetz simpson will print each file with a leading header giving the file name. nl trapetz simpson prints line numbers but no file names. You'll need to use either awk or some shell glue to combine the two.

for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done

Here's an awk solution which prints the byte count at the bottom:

awk '
    FNR == 1 && NR != 1 {print "end", FILENAME, bytes, "bytes"; bytes=0}
    END {print "end", FILENAME, bytes, "bytes"}
    FNR == 1 {print "begin", FILENAME }
    1 {bytes += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson

tail -n +1 trapetz simpson will print each file with a leading header giving the file name. nl trapetz simpson prints line numbers but no file names. You'll need to use either awk or some shell glue to combine the two.

for x in trapetz simpson; do
  echo "$x: $(wc -c <"$x") bytes"
  nl "$x"
done

Here's an awk solution which prints the byte count at the bottom:

awk '
    FNR == 1 && NR != 1 {print "end", fn, chars, "characters"; bytes=0}
    END {print "end", fn, chars, "characters"}
    FNR == 1 {print "begin", FILENAME; fn=FILENAME}
    1 {chars += 1 + length; printf "%7d ", FNR; print}
' trapetz simpson
Source Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
Loading