Tag Archives: terminal

How to display a file from one line number to another in Linux

If you need to read a file and print from a range of line numbers (including the last one), you can use the command as shown below.

cat <filename> | awk 'NR >=linenumber1 && NR <=linenumber2'

To read and display a file along with the line numbers, you can use the following format:.

cat -n <filename>

Example:

cat -n sample.txt

display line number
For example:

To print lines starting from line 2 to line 7, then you can use the following command.

cat sample.txt | awk 'NR >=2 && NR <=7'

Sample Output:

use cat and awk to print range of line numbers in linux
If for any reason you need to display the line numbers along with the output, then you can pass the -n argument to cat before piping it to awk as shown below.

cat -n sample.txt | awk 'NR >=2 && NR <=7'

Sample Output:

print with line numbers

[Note: There are multiple methods to do the same procedure. This method is intended for beginners who are just getting started in Linux.]

Hope this helps!

If this article helped you, do leave a comment below and like us on Twitter and Facebook. Cheers!

Source: Link

Double quotes not working in Linux terminal – [Solution]

I encountered an issue in my CentOS VM where whenever I type the  (single quote) or the  (double quotes) in the terminal, they don’t get displayed. I did the following to fix the issue:

In your terminal window, type the following:

# setxkbmap -layout us

You should now be able to use single, double quotes or tilde symbols in your terminal.

The above command simply changes the keyboard layout to English (US) and this is under the assumption that you are actually using a English (US) keyboard in your PC.

[Note: English (US) layout is different from English (US) International keyboard layout].

You can check the screenshot below for reference.

setxkbmap -layout us

Thanks and credits to this post that helped me resolve this issue.

Feel free to leave a comment in the comments section down below. Happy troubleshooting! Cheers!