Questions tagged [cut]

A Unix shell command that breaks input into fields, which can be selected for output, based on a delimiter.

cut is often the easiest way to split input lines or to extract only parts from them. If the rule how to split a line into fields can be expressed with a single character, cut should be used insead of the more powerful tools sed or awk.

cut can select fixed ranges from the input line, be they bytes or characters.

The perfect match for cut is, of course, .

For Prolog's cut, see

In scientific software for statistical computing and graphics, the function cut partitions elements of a numeric vector into bins.

1687 questions
13
votes
5 answers

Unix cut: Print same Field twice

Say I have file - a.csv ram,33,professional,doc shaym,23,salaried,eng Now I need this output (pls dont ask me why) ram,doc,doc, shayam,eng,eng, I am using cut command cut -d',' -f1,4,4 a.csv But the output remains ram,doc shyam,eng That means…
ghosh'.
  • 1,567
  • 1
  • 14
  • 19
12
votes
4 answers

Get lower and upper bounds from `cut` as numeric values

I've read this question here: Convert continuous numeric values to discrete categories defined by intervals However, I would like to output a numeric (rather than a factor), specifically the numeric value of the lower and/or upper bounds (in…
Andrew
  • 516
  • 1
  • 6
  • 17
12
votes
4 answers

Should I use cut or awk to extract fields and field substrings?

I have a file with pipe-separated fields. I want to print a subset of field 1 and all of field 2: cat tmpfile.txt # 10 chars.|variable length num|text ABCDEFGHIJ|99|U|HOMEWORK JIDVESDFXW|8|C|CHORES DDFEXFEWEW|73|B|AFTER-HOURS I'd like the output to…
user3486154
  • 121
  • 1
  • 1
  • 3
12
votes
1 answer

How to cut multiple columns from several files and print the output to different files

I have several files and I only want to take specific columns from it. At the moment, I am using the following code: $cut -f 1,2,5 AD0062-C.vcf > cutAD0062.txt However, to speed up the process I was wondering if I could cut the same columns (fields…
user1458512
  • 159
  • 1
  • 1
  • 8
11
votes
2 answers

xcode cut last characters from string

I am working on a Xcode program and need to cut the last 5 characters from a string. Does anybody know how to cut the last 5 characters from a NSString?
DennisW83
  • 111
  • 1
  • 1
  • 3
11
votes
2 answers

How to extract the first column from a tsv file?

I have a file containing some data and I want to use only the first column as a stdin for my script, but I'm having trouble extracting it. I tried using this awk -F"\t" '{print $1}' inputs.tsv but it only shows the first letter of the first column.…
Saeko
  • 421
  • 1
  • 4
  • 14
11
votes
4 answers

Shell: How to cut a single string with "Cut"?

i'm trying to cut a string into the shell. I'd like to do something like: cut -d' ' -f1 "hello 12345 xyz" but the problem is that cut accept a file, so if i pass the string to it, it tries to open the unexistent file called "hello 12345 xyz" and…
Ryno
  • 403
  • 2
  • 7
  • 11
10
votes
1 answer

Linux, How to using cut command with delimiters double quote?

i have a a line of text file contain this : $gVER = "4.027.160921.1"; how to using cut in linux to delete double quotes and also the last (;), i just want to put the numbers value only. what i already try is this : exec( "cat…
yosafat
  • 243
  • 1
  • 4
  • 17
10
votes
2 answers

using Linux cut, sort and uniq

I have a list with population, year, and county and I need to cut the list, and then find the number of uniq counties. The list starts off like this: #Population, Year, County 3900, 1969, Beaver 3798, 1970, Beaver 3830, 1971, …
user2615699
10
votes
6 answers

How to cut part of a string in c?

I'm trying to figure out how to cut part of a string in C. For example you have this character string "The dog died because a car hit him while it was crossing the road" how would a function go making the sentence "a car hit him while crossing the…
answerSeeker
  • 2,692
  • 4
  • 38
  • 76
10
votes
2 answers

replacement for cut --output-delimiter

I created a script that was using cut -d',' -f- --output-delimiter=$'\n' to add a newline for each command separated value in RHEL 5, for e.g. [root]# var="hi,hello how,are you,doing" [root]# echo $var hi,hello how,are you,doing [root]# echo…
Marcos
  • 845
  • 3
  • 10
  • 21
9
votes
3 answers

Get the value of a textbox during cut event

I have trapped the cut event (jquery) on a textbox. What I want is to get the text on the textbox during the cut event is triggered. I've tried accessing the data the user cut via evt.originalEvent.clipboardData.getData('text') but returns…
ptheofan
  • 2,150
  • 3
  • 23
  • 36
9
votes
1 answer

Cut polygons using contour line beneath the polygon layers

I would like to cut a polygon layer, according to the elevation, into two parts (upper and lower part). The polygon might convex or concave, and the position to cut might vary from each other. The contour line has an interval of 5m, which means I…
Marco
  • 505
  • 9
  • 18
9
votes
1 answer

How to grep rows that have value less than 0.2 in a specific column?

ID RT EZ Z0 Z1 Z2 RHO PHE 1889 UN NA 1.0000 0.0000 0.0000 0.8765 -1 1890 UN NA 1.0000 0.0000 0.0000 0.4567 -1 1891 UN NA 1.0000 0.0000 0.0000 0.0012 -1 1892 UN NA 1.0000 0.0000 …
user3446084
  • 149
  • 1
  • 1
  • 4
9
votes
3 answers

Cutting the column including size

I want to cut the column which include the size of files . I use ls -l to view info about files in current localization . I save info about file in txt file ls -l > info.txt , and now I want to cut the column including size . I do cat info.txt | cut…
user2344333
  • 147
  • 1
  • 1
  • 9