Linux Commands: Divide a file into several parts


cut-Linux Command

cut command- Divide a file into several parts

Syntax: cut [OPTION]... [FILE]...

 

Description: Prints selected parts of lines (of a text file), or, in other words, removes certain sections of a line. You may wish to remove things according to tabs or commas, or anything else you can think of...
Options for cut:
?d ??? allows you to specify another delimiter, for example ':' is often used with /etc/passwd:
cut ?d ':' (and probably some more options here) /etc/passwd

?f ??? this option works with the text by columns, separated according to the delimiter. For
example if your file had lines like "result,somethingelse,somethingelse" and you only wanted
result you would use:
cut ?d ',' ?f 1 /etc/passwd
This would get you only the usernames in /etc/passwd

"," (commas) ??? used to separate numbers, these allow you to cut particular columns. For
Example:
cut ?d ':' ?f 1,7 /etc/passwd
This would only show the username and the shell that each person is setup for in /etc/passwd.

"?" (hyphen) ??? used to show from line x to line y, for example 1?4, (would be from lines 1
to line 4).
cut ?c 1?50 file1.txt
This would cut (display) characters (columns) 1 to 50 of each line (and anything else on that
line is ignored)

?x ??? where x is a number, to cut from line 1 to "x"

x? ??? where x is a number, to cut from "x" to the end.
cut ?5, 20?, 8 file2.txt
This would display ("cut") characters (columns) 1 to 5, 8 and from 20 to the end

Related:

Other Linux Commands:
alias , break , builtin , cal , case , cat , cd , cfdisk , chgrp , chmod , chown , chroot , cksum , cmp , comm , continue , cp , cron , crontab , csplit , cut , date , dc , dd , declare , df , diff , diff3 , dir , dircolors , dirname , dirs , du , echo , egrep , enable , env , eval , exec , expand , export , expr , factor , false , fdformat , fdisk , fgrep , find , fmt , fold , for , fsck , function , getopts , hash , hashcharacter , head , history , hostname , id , if , import , install , join , kill , less , let , ln , local , locate , logname , logout , lpc , lpr , lprm , ls , m4 , man , mbadblocks , mkdir , mkfifo , mknod , more , mount , mtools , mv , nice , nl , nohup , passwd , paste , period , popd , pr , printf , ps , pushd , pwd , quota , quotacheck , quotactl , ram , rcp , read , readonly , return , rm , rmdir , rsync , Run , sdiff , sed , select , seq , set , shift , shopt , shutdown , sleep , sort , split , su , sum , symlink , sync , tac , tail , tar , tee , Test , time , times , top , touch , tr , traceroute , true , tsort , tty , Type , ulimit , umask , uname , Unexpand , uniq , units , unset , unshar , until , useradd , usermod , users , uuencode , watch , wc , whereis , which , while , who , xargs , yes ,
Live2Support.com :
Product - Benefits - Features - How Does it Works - Pricing - SSL Certificates - Signup - Contactus - Login - Submit Resources