Created
June 17, 2016 09:43
-
-
Save eniuz/d0503630090cde96fbb7ed2bf8a8c099 to your computer and use it in GitHub Desktop.
get 10/20 lines from the top of the file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
head command example to print first 10/20 lines | |
head -10 bar.txt | |
head -20 bar.txt | |
sed command example to print first 10/20 lines | |
sed -n 1,10p /etc/group | |
sed -n 1,20p /etc/group | |
awk command example to print first 10/20 lines | |
awk 'FNR <= 10' /etc/passwd | |
Type the following awk command to display first 20 lines of a file named “/etc/passwd”: | |
awk 'FNR <= 20' /etc/passwd | |
perl command example to view first 10/20 lines of a file | |
Type the following perl command to display first 10 lines of a file named “/etc/passwd”: | |
perl -ne'1..10 and print' /etc/passwd | |
Type the following perl command to display first 20 lines of a file named “/etc/passwd”: | |
perl -ne'1..20 and print' /etc/passwd | |
Sample outputs from sed, awk, head, and perl commands: | |
root:x:0:0:root:/root:/bin/bash | |
bin:x:1:1:bin:/bin:/sbin/nologin | |
daemon:x:2:2:daemon:/sbin:/sbin/nologin | |
adm:x:3:4:adm:/var/adm:/sbin/nologin | |
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin | |
sync:x:5:0:sync:/sbin:/bin/sync | |
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown | |
halt:x:7:0:halt:/sbin:/sbin/halt | |
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin | |
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment