How to …

Get number of lines of a text file and assign this value to a variable

num_lines=($(wc -l <file_name>))

Ex:
Fruits.txt

Annona
Coconut
Papaya
Mango
Nuts

We have 5 lines.

num_lines=($(wc -l Fruits.txt))
echo "The number of lines in Fruits.txt is $num_lines"

It will print “The number of lines in Fruits.txt is 5”

Write log of a command in terminal to file

<command> > <log_file>

Ex:

echo "Have a nice working day!" > happy.txt

Result:
happy.txt

Have a nice working day!

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