Menghitung jumlah baris dalam file teks

Cara mudah menghitung jumlah baris dalam file teks. Trik ini bisa dipakai oleh siapa saja tanpa bulu pandang for the sheer curiosity.

cat -n

cat – concatenate files and print on the standard output.

Perintah cat sudah sering saya tulis di sini. Kalau digabung dengan opsi -n bisa lebih dahsyat!

$ cat karma.txt -n
1	everything
2	you
3	give
4	sooner
5	or
6	later
7	comes
8	back
9	to
10	you

wc -l

wc – prints newline, word, and byte counts for each file, and a total line if more than one file is specified. A word is a non-zero-length sequence of characters delimited by white space.

Perintah wc juga sering saya bahas di sini. wc -l lebih ringkas dibanding cat -n sebab cuma menampilkan jumlah baris.

$ wc -l < karma.txt
10

Baik cat -n maupun wc -l tidak menghitung baris kosong. Jadi yang dihitung cuma baris yang ada teks saja. Maksudnya, kalau ada teks --> [ENTER 2x] --> teks, [ENTER 2x] tak dihitung.

Selamat mencoba, semoga bermanfaat.

everything
you
give
sooner
or
later
comes
back
to
you
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s