Skip to main content

Questions tagged [cut]

For questions pertaining to cut, a filter program which extracts fields or columns of each line of input. Use this tag for questions about cut itself or questions about issues arising from using the cut utility.

Filter by
Sorted by
Tagged with
1 vote
1 answer
28 views

How do I format the output of cut to the following format? [duplicate]

last part of the command: | cut -d' ' -f3 output: 4 10 required format: 4,10 I'm guessing echo (and sort?) is to be used in some way, but I can't quite place my finger on it.
kesarling's user avatar
  • 159
1 vote
0 answers
33 views

pfSense (FreeBSD) - tail -f not showing entire log when filtering with cut or sed [duplicate]

I have a strange problem when trying to display logs on pfSense (and I can reproduce the same problem on Ubuntu server also). The problem is this (with examples): I'm trying to display a running dhcp ...
Artur Meinild's user avatar
0 votes
2 answers
51 views

Unexpected cut output

I am getting an unexpected output from cut. I would expect no output since there is no third field based on the specified delimiter. The first two lines intentionally use commas as delimiters, and the ...
ayeieye's user avatar
0 votes
1 answer
62 views

cut -d – Delimiter is still shown in the output. How to remove it simply?

Why the delimiter is still shown in the output? I thought field 2 and 4 would be shown without the - delimiter. How to use cut command to not show at the same time the delimiter itself used to ...
Faxopita's user avatar
  • 179
0 votes
3 answers
93 views

How do I change the extension of a long filename quickly?

original file: a really really long name with spaces.ext target file: the same name.new-ext command: mv *part of the name that'll give a unique answer.ext $(echo $(ls -l | grep -i *.ext | cut -d ' ' -...
kesarling's user avatar
  • 159
4 votes
1 answer
425 views

Cut command stored in variable will not work

Can someone explain why I cannot store the cut command in a variable?? user:~$ echo "foo bii doo" | cut -d ' ' -f 2 bii # as expected # now put cut command into a variable: user:~$ c="...
archygriswald's user avatar
-1 votes
2 answers
136 views

Grep a log file for SQL queries and their execution time

I have an application log file that also captures the execution time for each executed SQL statement, like below:- Sample logs: I 2023-11-15 07:18:00.743Z 1760463 37 ZVRwqItu6aw-b8eejMLI_gAAAAU 1@...
Arpit Jain's user avatar
1 vote
4 answers
346 views

Retrieve the 1st and 5th column of a tab-separated file, convert the spaces in the 5th to tabs

I have a tsv file with tab-separated columns. I want to obtain the 5th column, which has space-separated values. Convert the space-separation to tab-separation and save as a new file. Attempt: cut -d&...
Anon's user avatar
  • 133
2 votes
2 answers
266 views

A shorter way to list all packages matching a string

When I search for a list of packages, I usually use dpkg -l|grep string|cut -d" " -f3|xargs libdouble-conversion3:amd64 libestr0:amd64 libeval-closure-perl libio-stringy-perl libunistring2:...
rubo77's user avatar
  • 29.4k
0 votes
2 answers
130 views

How to combine tr with xargs and cut to squeeze repeats

The top answer to this question demonstrates that cut can be used with tr to cut based on repeated spaces with < file tr -s ' ' | cut -d ' ' -f 8 I want to get the remotes of several Git repos in ...
Anil's user avatar
  • 221
1 vote
2 answers
91 views

How do I backslash-ignore a delimiter passed into cut?

I have the following use case: echo "some comment char '\;' embedded in strings ; along with inline comments" \ | cut -d';' -f 1 I want: some comment char ';' embedded in strings I get: ...
Chris's user avatar
  • 983
0 votes
3 answers
339 views

listing existing users sorted by date of creation using cut command

ASK: to use cut command to list all users to confirm a successful useradd. ISSUE: The list was very long and I had to scroll through output to find user. NEED: Sort by the date the user was created. ...
VintageDroid's user avatar
0 votes
0 answers
37 views

Truncate output to terminal width (colour and wide char aware) [duplicate]

I have the alias: trunc='cut -c -${COLUMNS:-80}' This works just dandy when text doesn't contain colours and wide characters. I could play with tput rmam and tput smam, but these don't actually ...
Tom Hale's user avatar
  • 31.2k
2 votes
4 answers
390 views

linux command using trim / cut / sed to cut few data in a file

I have the content like below in a /tmp/myfileslist test1/a/sample1.xls test2/demo.sh I want to remove .extentions and content before slash , also slash is to be removed.I want the output as sample1 ...
afrin's user avatar
  • 61
1 vote
4 answers
72 views

Extract substring between n and m delimiter

I want to write a for loop to obtain everything between the third / to the 4th . for a list of files. My attempt: for mcool_file in ./input/*.mcool; do while IFS= read -r id; do id | cut -...
Anon's user avatar
  • 133
1 vote
3 answers
1k views

Extract version number from github repo

Hello I'm trying to extract a version number from a github release site. Which I later need for a Ansible role. For example I want to get the exact neovim version number of the latest release from ...
edinazzu's user avatar
2 votes
2 answers
110 views

How can I assign values from text to variables?

I have this text: node1: connect command: ssh [email protected] password: qcipunbnctza node2: connect command: ssh [email protected] password: ejrpnnwsczpa node3: connect command: ssh [email protected]....
VladF's user avatar
  • 63
0 votes
2 answers
506 views

Choose columns with sort and cut in a csv with a comma delimiter ',' ignoring data on quotes with comma "text,text"

I am parsing a huge csv file with rows and columns with different parameters. However, some fields contain large descriptions within quotes that contain commas. How can I choose columns with sort and ...
infinity's user avatar
2 votes
1 answer
295 views

Rounding off negative decimal and positive decimal number

I would like to round off the below numbers to nearest wholenumber using awk command and copy it to another column say col11 and col12. can anyone help eg 1) column5,column6,,,,,column11,column12, ...
user558041's user avatar
1 vote
2 answers
1k views

How to pass a variable into the field option for the cut command (bash)

I have a tab delimited file with 2500 columns and 3000 rows. I would like to extract a specific column based on the header. By the way, this is being done in a while loop so each time a different ...
Sarah's user avatar
  • 49
-1 votes
1 answer
89 views

How to take only some values above a cutoff in a column

I have a file with 12 columns. In the 10th column I have values ranging from 0-100. However, I just need those values that are above 80. Rest, I want to be filtered out. may I know which command ...
YASIR's user avatar
  • 1
0 votes
4 answers
63 views

using find command in linux for filenames generated from previous command

I am trying to use find command like this cut -f 4 file.txt | awk 'NR>1' | find ./ -name After the awk command my input looks like this foo.c foo.txt abc.txt How can I feed the name of the file ...
user3138373's user avatar
  • 2,559
0 votes
2 answers
54 views

return a character found in a pattern

GOAL What is the simplet one-liner that can read the disk number and perform the mount command? The one-liner will execute the equivalent of: ./mountEFI.command disk3 BACKGROUND user@mac ~ % ...
gatorback's user avatar
  • 1,394
0 votes
1 answer
270 views

Remove all text between (and including) a forward-slash and a comma

I have a .txt document that contains thousands of strings all with a similar layout, but some of the lines have additional info I do not want. Here’s an example: 202212_08,ABC123/A1234,AB,,C123 ...
Brendan's user avatar
-1 votes
3 answers
257 views

Replace dot before pattern using sed or awk

I can get the two inputs: 67.1.3.0.0.221111.1, or 89.1.5.0.0.221112 I want to replace the dot before the date pattern (221111) with an underscore. Input 67.1.3.0.0.221111.1, output 67.1.3.0....
Vishal Mahajan's user avatar
0 votes
2 answers
251 views

I am trying to split the path but getting correct commands

I am trying to split the path but not getting correct commands i.e. /bin/bash/test/path/to/split and should be split/cut in two parts delimited with string i.e. split on string /to/. Expected output: /...
Hrishi's user avatar
  • 1
1 vote
1 answer
231 views

command for multiple input and multiple output

I am performing some operations using the grep, sed, and cut commands on a Linux machinete: zgrep -A1 "^module" *.v.gz | sed -n -e 's/^\(module \)*\(.*(.*)\).*$/\2/p' | cut -f1 -d"(&...
Santhosh Nayak D.'s user avatar
0 votes
3 answers
80 views

script using linux command to search word

I have the file, In the file data few lines have only one word, if such a case is present i want to print following line as the present line can I get some tips for this grep -E "module" ...
Santhosh Nayak D.'s user avatar
0 votes
1 answer
63 views

How can I fetch branch names from the git branch -r output

When I do git branch -r, each line seems prefixed with the remote name. $ git --no-pager branch -r origin/feature/XXX-NNN origin/feature/XXX-NNN origin/feature/XXX-NNN $ How can I fetch those ...
Jin Kwon's user avatar
  • 510
3 votes
1 answer
215 views

Why is the stdout line buffering for cut -c differ from cut -b?

Our RHEL 7 machines have great long Log files and I asked about buffering of cut in this question. That question remains but a bit of experimentation showed a different issue. I decided to try using ...
user1683793's user avatar
0 votes
1 answer
37 views

Unable to get multicharacter field in fzf preview

_select () { apt-cache search '' | fzf \ --prompt='search: '\ --marker="M" \ --ansi \ --layout=reverse \ --cycle \ --multi \ --inline-info \ --preview "...
testoflow's user avatar
  • 117
0 votes
1 answer
149 views

make cut output a certain term when no delimiter found

I am looking for extensions of files and cut simply gives the filename if the file has no extension so I am looking to make cut give a "extensionless" when no '.' is found I am using this as ...
stacking and exchanging woohoo's user avatar
-2 votes
2 answers
644 views

Need to get the date from the name of the file

I have a file name abcd_abcd_12302022.csv, I have extracted the date from the file name using cut -c 11-18 and the date is 12302022. I have tried below command to be in 12/30/2022 but getting ...
ImSahil's user avatar
-1 votes
2 answers
6k views

AWK or grep with cut. Need help cutting a field

I have this file and need to cut field 3 which should be cut - f 3. Right? I am using this code and its absolutely not doing anything for me. grep '^2014-' FileName | cut - f 3| less
B York's user avatar
  • 1
1 vote
2 answers
276 views

cut and compare string in file

I have file that contaian the following lines : 3 5 asd/sdf/rdc fgd/ghw/rtt 4 7 axd/sdf/rdc axd/ghw/ert 8 2 drf/sdf/uhg fgd/ghw/gcd I want to compare only the first names in coloums 3 & 4 and ...
Oren Hamama's user avatar
0 votes
3 answers
488 views

awk not working in extracting fields from csv file

This is probably a silly question but I'm a beginner. Currently having trouble extracting fields from a csv file. Ideally, I want to print it out with li tags with the third column printing in ...
pierogie's user avatar
1 vote
2 answers
86 views

Arranging the lines in required order

A file contains lines as follows: acb/xyz/row<t> acb/xyz/row<t> abc/xyz/row<1> abc/xyz/row<1> abc/xyz/row<0> abc/xyz/row<0> abc/xyz/row<3> abc/xyz/row<3>...
Manjunath's user avatar
0 votes
0 answers
569 views

Writing a File with CSV Header Column and Unique Column Values in Bash

I have a bunch of csvfiles that I'm importing into a database. I'd like to get a preview of the unique values in each column to help me create the tables. I've written a script that takes a input csv ...
студент001's user avatar
0 votes
1 answer
80 views

What does '-' mean in a Shell script?

I'm trying to understand a script I have and it has a line that says cut -d '-' -f 1 I don't understand what '-' does here
zwz's user avatar
  • 11
0 votes
1 answer
283 views

Word before and after a "=" symbol

I am trying to write some code which displays the word before an = symbol and after it based on user input. For example, if a user enters Name=john the output would be: The variable is called: Name ...
Fmiller's user avatar
1 vote
2 answers
37 views

substitute 2 substrings from a single line in a file into 2 different lines in a different file from command line

I have a text file with however many lines. One line is: fixed_stringA = 123, fixed_stringB = 456 I have a second text file (again with however many lines). These 2 lines are in this order, in middle ...
ded's user avatar
  • 113
1 vote
4 answers
924 views

How can I get the lsblk-devices that are NOT in use

root@pve-virt-01:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 250G 0 disk ├─sda1 8:1 0 1007K 0 part ├─sda2 8:2 ...
jsterr's user avatar
  • 1,341
-3 votes
1 answer
118 views

Shell to Bash Script [closed]

fld=$(mediainfo Fixing\ One\ of\ Linux\'s\ Biggest\ Flaws.mp4 | awk -F " : " 'NR==10 {print $2}'); mkdir "$fld" I'm attempting to get Performer from mediainfo's output. Line ...
Dark_Stoner's user avatar
4 votes
2 answers
986 views

cut /etc/passwd but without colons (:) in the resulting set of fields

I want to list the username, id and group on /etc/passwd using the following format: username uid gid I have used the following: cut -d: -f1,3,4 /etc/passwd But it returns username:uid:gid. How can I ...
LearningLinux's user avatar
0 votes
1 answer
128 views

Cut last value of a string [duplicate]

My data is like (a.txt) allheartweb.com whoisdatacenter.com domainsanalytics.com covercian.co.uk I want to extract all TLD from there My code is cut -d "." -f 2 a.txt its show me com com ...
Amit Singh's user avatar
3 votes
1 answer
794 views

Cut or Awk to save lines on array in bash

I have a scenario that I have to put lines of a file .txt inside an array, example of file content; type of host | | first host | | | | second host | | | | | | same ip ...
Carlos Gomes's user avatar
1 vote
2 answers
5k views

split string using a substring as delimiter and get the later part

Here is my string LIBRARY_TRGT_CANV,CANV_MATCH<anything> I wish to get all the text after last occurance of our delimiter which is _TRGT_: Desired output: CANV,CANV_MATCH<anything> ------ ...
Ashar's user avatar
  • 511
1 vote
4 answers
297 views

How to get first Character of every underscore delimiter using bash

Hi Team there is a scenario where table name such as head_must_report customer_report_sub_division country_code_universe_nation_part However using cut command output should be as below. Note: table ...
Gyari's user avatar
  • 15
0 votes
0 answers
115 views

What is %8F URL encoding character so that stops cut command?

I am working on URL-escape codes. I have a file named escapeCodes which haves all the codes : ! %21 %21 " %22 %22 # %23 %23 $ %24 %24 ... ~ %7E %7E %7F %7F € ...
user avatar
0 votes
4 answers
125 views

concise but readable way to extract the numerical value after the substring "mode:" in a shell script

I have this string: DMT mode 4: 640x480 @ 60Hz 4:3, clock:25MHz progressive I want to extract from it the mode number (the part before the first :), which in this example is 4. As you might ...
Al Ro's user avatar
  • 223

1
2 3 4 5
9