So, cut command is used to cut out selected fields of each line of a file. The cut command uses delimiters to determine where to split fields.
Syntax: cut [options] filename
- A pathname of an input file. If no file operands are specified, or if a file operand is -, the standard input will be used
- The list following -c specifies character positions
- The character following -d is the field delimiter
- select only these fields on each line
- Select only the bytes from each line as specified in LIST
- For example, let’s say you have a file named data.txt which contains the following text: one two three four five alpha beta gamma delta epsilon
- Moreover, In this example, each of these words is separated by a tab character, not spaces. The tab character is the default delimiter of cut, so it will by default consider a field to be anything delimited by a tab.
- To “cut” only the third field of each line, use the command:
$ cut -d’ ‘ -f 3 data.txt
let’s say you want the third field and every field after it, omitting the first two fields. In this case, you could use the command:
$ cut -d’ ‘ -f 3- data.txt
three four five gamma delta epsilon
$ cut -c 3 file.txt
For example, to output only the third-through-twelfth character of every line of data.txt, use the command:
$ cut -c 3-12 data.txt
e two there
pha beta g
paste command is used to paste the content from one file to another file. It is also used to set column format for each line.
Syntax: paste [option] file
- Paste prints lines consisting of sequentially corresponding lines of each specified file. In the output, the original lines are separated by TABs. Moreover, The output line is terminated with a newline.
- Also, Specify of a list of delimiters.
- Paste one file at a time instead of in parallel.
- also, A pathname of an input file. It – is specified for one or more of the file s, the standard input will be used.
$ cat > a
$ cat > b
- Dedicated server
- Virtual server
$ paste a b
- Unix Dedicated server
- Linux Virtual server
$ paste -d”|” a b
- Unix|Dedicated server
- Linux|Virtual server
$ paste –s a b
- Unix Linux Windows
- Dedicated server Virtual server
$ paste –s –d”,” a b
- Unix, Linux, Windows
- Also, Dedicated server, Virtual server