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
2 votes
2 answers
232 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
  • 27.9k
0 votes
2 answers
55 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
0 votes
1 answer
35 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
  • 903
0 votes
4 answers
62 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
33 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
  • 28.9k
2 votes
4 answers
251 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
  • 51
1 vote
4 answers
62 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 -...
melolili's user avatar
  • 113
1 vote
3 answers
264 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
102 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
  • 43
0 votes
2 answers
238 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
245 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
411 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
56 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
57 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,441
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,214
0 votes
1 answer
198 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
159 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
110 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
163 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
65 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
50 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
  • 480
3 votes
1 answer
152 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
34 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
136 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
209 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
2k 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
241 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
241 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
82 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
413 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
54 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
236 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
32 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
615 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,311
-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
848 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
90 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
701 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
4k 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
  • 459
1 vote
4 answers
234 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
93 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
82 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
  • 203
1 vote
1 answer
652 views

Using comma delimited data as separate arguments to command

I am using xargs in conjunction with cut, but I am unsure how to get the output of cut to a variable that I can pipe to use for further processing. So, I have a text file like so: test.txt: /some/path/...
JohnJ's user avatar
  • 135
-1 votes
3 answers
539 views

How to use cut to trim the first x variable spaces [closed]

I have a file that is like this: 67 lol 143 hi 21 test 1 ciao 5 lo I want to remove the spaces. 67 lol 143 hi 21 test 1 ciao 5 ...
Allexj's user avatar
  • 261
0 votes
1 answer
84 views

Cut Command Question - Column pulls other column if missing data

I have an example file on a Linux system: Sally Smith John Smith Bill Sam When I run this command I get the first column: $ cut -d " " -f1 test.txt Sally John Bill Sam When I run this ...
AnthonyB's user avatar
1 vote
0 answers
22 views

cut file and overwrite file [duplicate]

Let's say I have file.txt water 1 lorem 0 ipsum 0 I cut the last column and redirect output to file itself with this: cut -d' ' -f 1 file.txt > file.txt I expect current content of file.txt is ...
Muhammad Ikhwan Perwira's user avatar
0 votes
1 answer
68 views

cut command: how use the delimiter to be considered/included within the field position?

I want extract the version release of some file .gz/.zip installers. Therefore if is executed (shown in this way for simplicity purposes): echo "apache-maven-3.8.4-bin.tar.gz" | cut -d'-' -f ...
Manuel Jordan's user avatar
0 votes
5 answers
268 views

Delete columns that contains only numbers

I have a table that containes some data and I need to delete the columns that contains only number (Nr.,Cod,Tiraj): Nr. Autor Titlu Cod Tiraj Tara 1 Gauss Carl ...
Luis Fernando Scripcaru's user avatar
2 votes
2 answers
497 views

Get the Absolute Path from feh

The feh command allows you to view images within a folder recursively: feh --recursive --auto-zoom While viewing images, it also allows you to associate custom commands with keys 0-9 on your keyboard....
Lonnie Best's user avatar
  • 4,965
0 votes
3 answers
5k views

How to use cut to get the last field of /proc/pid/maps?

I need to do some processing on the list of .so loaded by a process. I tried cut with space as a delimiter but I didn't succeed. How to correctly pipe the output of cat /proc/PID/maps into cut to get ...
boredaf's user avatar
  • 171

1
2 3 4 5
9