How to display/print nth line in Linux Command Line [Quick Tip]

Problem:

Imagine a scenario where you need to print or display only the nth line of the file. For e.g, suppose you have a file with 50000 line and you want to print just the 100th line.

Solution.

My favorite way to do so is by using a combination of tail and head command. Here is the commands that can be used for the mentioned purpose:

tail -n +100 filename | head -n1
Tail -n +100 gives all the lines starting from 100th line. Then we use head -n1 which gives the first line. A combination of bot gives the 100th line.
The example can be made generic by replacing 100 by your desired value.

How to solve: No wireless networks in Ubuntu 12.04, 11.10 and 11.04

Problem:

Recently I installed Ubuntu 11.04 (wireless was working while installing) on my Dell Inspiron N4010 which uses Broadcom Wireless Adapter (How to know which network adapter you are using?). Wireless networks were even available when I used it for the first time after installing. Then there were message from Ubuntu that restricted drivers are available for Broadcom STA (BCM4311) (why did it ask me to download the wireless drivers when wireless was working on the first hand..??). Any ways, I said, why not? I clicked on the activate button. It installed the driver and asked me to restart the computer. I restarted it and there you go. Wireless is on. But it detects no networks. I know there are wireless networks but Ubuntu is not detecting any wireless networks.

Reason:

The reason what I think is some compatibility issues (it’s probably a bug in 11.04) with this version of Ubuntu and the restricted driver because same driver was working quite well in previous versions of Ubuntu.

Solution:

Here is what you need to do. Use other Broadcom drivers. Download these drivers (from Windows or through wired network or a friend’s computer or from wherever you are reading this article :) ).

For 32 bit: http://ie.archive.ubuntu.com/ubuntu/pool/restricted/b/bcmwl/bcmwl-kernel-source_5.+bdcom-0ubuntu5_i386.deb

For 64 bit: http://ie.archive.ubuntu.com/ubuntu/pool/restricted/b/bcmwl/bcmwl-kernel-source_5.+bdcom-0ubuntu5_amd64.deb

(Don’t know which Ubuntu you are using? Click here: Check you Ubuntu architecture)

Now remove the previous drivers in Ubuntu 11.04 by using: sudo apt-get remove bcmwl-kernel-source

Now install the appropriate driver (you have downloaded from the above links). Restart your computer. If restarting doesn’t work try shut down and then start it (strange…but works). Enjoy :)

Alternate Solution 1:

If you could connect through a wired network, this solution might work for you. (If not then check here). The problem is with STA drivers so better to deactivate/uninstall it.

Alternate Solution 2:

People who cannot solve the problem with the above specified method may want to try this one. Here you go:

  • open the ‘Synaptic Package Manager‘ (if you are using Ubuntu 11.10 then install it first from the software cemter) and search for ‘bcm’
  • uninstall the ‘bcm-kernel-source‘ package
  • make sure that the ‘firmware-b43-installer‘ and the ‘b43-fwcutter‘ packages are installed
  • type into terminal:

    cat /etc/modprobe.d/* | egrep '8180|acx|at76|ath|b43|bcm|CX|eth|ipw|irmware|isl|lbtf|orinoco|ndiswrapper|NPE|p54|prism|rtl|rt2|rt3|rt6|rt7|witch|wl' 

    (you may want to copy this till the end if it is not visible properly) and see if the term ‘blacklist bcm43xx‘ is there

  • if it is, then type cd /etc/modprobe.d/ and then sudo gedit blacklist.conf put a # in front of the line: blacklist bcm43xx then save the file (I was getting error messages in the terminal about not being able to save, but it actually did save properly).
  • reboot
Hopefully this works for you all!
Questions, suggestions and feedbacks are welcomed. A word of thanks is always appreciated. And if you like the article and the blog then please subscribe to stay in touch.

Sources: ubuntuforums, askubuntu