Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [cut]

cut is a filter program which extracts fields or columns of each line of input.

-1
votes
2answers
17 views

Swapping the contents of two columns

I am trying to understand cut better and moving cut data to another file. I have a file called numbers with two columns. Each column is separated with one tab. I am trying to swap the columns by ...
2
votes
3answers
179 views

How to get single character after space?

How can I obtain below output? I want the first field as it is and a single character after space. echo "Hello world" Hellow If it also has a 3rd field than the beginning character of the 3rd field ...
0
votes
3answers
84 views

Regarding “<”, “<<”, and reading files [closed]

I know that I can do tr a b < file, but how do I do that for ls? So for example, How to feed ls -l a list of files from a 'file'. I tried the below and it did't work. $ cat>test A B C $ ls -l &...
61
votes
5answers
148k views

Replace multiple spaces with one using 'tr' only

I have a file, f1.txt: ID Name 1 a 2 b 3 g 6 f The number of spaces is not fixed. What is the best way to replace all the white spaces with one space using only tr? ...
3
votes
4answers
153 views

How to grep and cut numbers from a file and sum them

I have a log file. For every line with a specific number, I want to sum the last number of those lines. To grep and cut is no problem but I don't know how to sum the numbers. I tried some solutions ...
0
votes
2answers
6k views

Bash to join columns from multiple files

I have around 20 files in different folders for which I have created a separate file called pathtofiles.in which lists path information: /home/users/gray_wolf/unix/File_1.tsv /home/users/gray_wolf/...
0
votes
4answers
82 views

How can I delete everything but an alphanumeric pattern?

I have a file that has a lot of junk and special characters as well. I want to keep a particular alphanumeric pattern and ignore everything else - e.g AB123456789 - I want to extract only this keyword ...
-1
votes
3answers
2k views

How to filter log file for string inside single quotes?

I have a log file, which outputs information this way: 2016-01-01: foo bar fnord 2016-01-01: this is static 'this is of interest' some blob bar 2016-01-01: this is static 'this is of interest' some ...
198
votes
4answers
268k views

How to define 'tab' delimiter with 'cut' in BASH?

Here is an example of using cut to break input into fields using a space delimiter, and obtaining the second field: cut -f2 -d' ' How can the delimiter be defined as a tab, instead of a space?
0
votes
1answer
906 views

Fetch second and fourth column from a file

Problem Statement I am not able to get the values in second and fourth column. Tried grep -i "AUGC\|AACN\|AACY" output.csv | cut -d ',' 2,4 DATA success,1234,["madhu",{'first',[{'last',18}]},"I0",...
12
votes
3answers
3k views

Can not use `cut -c` (`--characters`) with UTF-8?

The command cut has an option -c to work on characters, instead of bytes with the option -b. But that does not seem to work, in en_US.UTF-8 locale: The second byte gives the second ASCII character (...
0
votes
2answers
57 views

How to insert a line in a file after certain bytes

Let's say I have a large file (several gigs) with n lines in it. I would like to add/insert a line after k bytes offset, from the beginning of the file, then what would be the fastest way to achieve ...
-1
votes
2answers
2k views

Replace special characters in specific field

how to replace special character in specific field? INPUT xxxx,11/2019,xxx OUTPUT xxxx,11,2019,xxx As you see that am looking to replace / with , in $2 only. How achieve that?
0
votes
3answers
73 views

Print only the multiple first characters

I have a big text file I want to print only the first 4 and the first 5 and the first 8 characters of each line in one command line. For example I have the lines: 123456789ab ABCdefgih55 So the ...
2
votes
3answers
2k views

how to pipe the output of cut to the foreach command?

I have the cut command I want that grabs the first word in each line of a file. I then want to put each word from the cut command into a foreach. I then want to do a grep command inside the body of ...
24
votes
8answers
2k views

Is piping, shifting, or parameter expansion more efficient?

I'm trying to find the most efficient way to iterate through certain values that are a consistent number of values away from each other in a space separated list of words(I don't want to use an array)....
0
votes
1answer
2k views

wget: Retrieving a list of URLs when modifying input data file on the fly

This issue is currently driving me up the wall. It just does not work as it should. I have a file inp with audio samples to download where I preserved the internal ID number by parsing some other ...
0
votes
4answers
153 views

grep and cut text from unstructured file?

From below 3lines I need to grep and cut jar file name only. How to grep jar name from the line and cut from there. Downloading:https://repo.maven.apache.org/maven2/org/springframework/spring-aop/5....
0
votes
3answers
53 views

Get a certain column of an output with content aligned right and some columns not always filled

This is a problem I often encounter, this time with the output of lsof, but I am searching for a general solution for such problems: selecting a column. Here I try to get the TYPE column of the ...
0
votes
0answers
68 views

sed/awk/grep/cut: multiply a number in an xml-attribute by factor of ten

I would like to multiply the attribute in viewBox of svg-files by a factor of ten. I want to change <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" version="1.1"> to <svg xmlns=...
15
votes
6answers
12k views

Can I make `cut` change a file in place?

The man page doesn't give me much hope, but I'm hoping it's an undocumented (and/or GNU-specific) feature.
6
votes
5answers
9k views

What the equivalent of “grep | cut” using sed or awk?

Say I had a config file /etc/emails.conf email1 = user@dinkum.dorg email2 = user@winkum.worg email3 = user@stinkum.storg and I wanted to get email2 I could do a: grep email2 /etc/emails.conf | ...
5
votes
1answer
5k views

Does the inverse command of cut exist?

I like using the cut command in Linux with the -c flag. However, I'm interested in finding a command that sort of does the set inverse of cut. Essentially, given the input: drwxrwxrwx 2 root root ...
0
votes
2answers
35 views

Find number of cores available in a given node

I need to fix the following piece of code. The code aims to determine the number of cores available in a given node. Step 1: Get the number of cores with TC=$(grep -c process /proc/cpuinfo) Step 2:...
0
votes
3answers
56 views

remove last number from string

I have a file test.txt, below the content: SCDE1 SF9 STR1D2 SREDF21 FRED STER2R4 I want to remove only the last character if it is the number, so the output should as below: SCDE SF STR1D SREDF2 ...
2
votes
3answers
251 views

find string and print first and last characters of line

I have files with hundreds of lines of varying length. I want to find each line with the string "New" and print the first 7 characters and the 10th from the last character. For example, cat file1....
0
votes
3answers
65 views

Script - Cutting various lines and sort them

i want to sort the process of one user by the percentage of cpu used. I tried this ps aux|tr -s " "|cut -f3 -d " "| sort -| grep "user" > file name does this work?
0
votes
2answers
41 views

Unix Split Function ~ select 2 different split words

I am using cut -d' ' -f1 to split a string in unix scripts. I want only f1 and f5, though, and I'm unable achieve this. I tried giving -f1-5, but that prints all the fields from 1st through 5th.
2
votes
1answer
89 views

Command modification

I'm using the following command to get the highest number of requests per second in a log file and it works well. grep "2017-02-22" "LogFile.log" | cut -c1-20 | uniq -c | sort -n | tail -n1 Now I ...
0
votes
1answer
45 views

grep pattern and the content after that, and remove others

I'm having a problem to grep specific keyword and its content. This is sample file, the actual file is larger than this. Example user@linux:~$ cat url.txt abcrandomtextdef another random text ...
1
vote
4answers
3k views

What does this command line (`echo $1 | xargs -n 1 basename | cut -d '.' -f1`) do? [closed]

I need to understand this command line: file=`echo $1 | xargs -n 1 basename | cut -d '.' -f1`
0
votes
1answer
58 views

Get string from filename to output file plus string inside same file

I have some directory with multiple files with the extention .failed This number of files can change every day. This files have the following format: file1_string2_1.failed: FHEAD|string2|...
1
vote
2answers
92 views

How to transpose x and y axis of table, using cut & paste shell commands

I need to transpose x and y axis, of a file of 450.000 × 15.000 tab separated fields, so I tried first with a small 5 × 4 test file named A.txt: x column1 column2 column3 row1 0 1 2 row2 ...
6
votes
4answers
874 views

“Cutting” id output

I need to write a script that would "cut" the output of the id command into three parts. For example: Let's say id gives this output: uid=12345(mylogin) gid=100(users) And my script should output ...
0
votes
3answers
90 views

Command to fetch the complete word in quotes

We have a value XX_EMAIL_GL_BTCH_ATTACH FCP_REQID=8830260 FCP_LOGIN="APPS/pwd" FCP_USERID=4807 FCP_USERNAME="USER" FCP_PRINTER="noprint" FCP_SAVE_OUT=Y FCP_NUM_COPIES=1 "XX WBP 8-501 Misc Receipts" "...
-2
votes
2answers
1k views

Using cut to manipulate a text file [closed]

I am having trouble manipulating the text in the screenshot. I need to change the file so only the IP address in the last column are left.
0
votes
3answers
34 views

cutting a directory name with multiple instances of the same delimiter (Shell)

I have directories I want to rename, for example: 10-00017_S9_L001_plasmidspades_careful I want to rename them to just the 10-00017_S9_L001 part I've tried to use the cut command echo "$filename" | ...
4
votes
1answer
180 views

cut command fields

I noticed these two different fields behaviors using cut command: bash:~$ var=`cat /proc/cpuinfo | grep 'model name' | uniq | cut -d ' ' -f 3,4,5,6,7,8 ` echo $var outputs Intel(R) Core(TM) i7-...
0
votes
3answers
120 views

Cut path to first four directories

I have several projects where I have to use the same command. The projects always are in /home/[username]/public_html/[prjectname]/ I'd like to run this command from every directory of my projects, ...
0
votes
1answer
297 views

Extract substring after delimiter using GNU awk or awk [duplicate]

I would like to extract substring after colon delimiter for my practical needs using GNU awk utility. For example I can extract the temperature of hdd value using cut as follows hddtemp /dev/sda | ...
2
votes
4answers
204 views

How to compare the 1st column of two files and if the strings match then print “true” [duplicate]

I have two files, say file1 and file2. file1: 91 | 2018-10-11 16:07:14 | bkwdv | 188.0000 | 77 | 2018-10-12 15:05:15 | wvwef | 94.0000 | file2: 77 | 2018-10-12 15:05:15 | wvwef | 94.0000 91 | ...
2
votes
2answers
186 views

Turning data collected vertically to a table

I have data was collected and saved in file "data.txt", in the following format: <$ MG_nr> </200>company-type:Engine1 </210>company-name:STR </220>address:XX </230>nr:...
0
votes
2answers
34 views

Using Cut inside a script to cut a column from a specific String

I have this file called viagens.txt: 2018-10-01:88020:88013:6:4.2 2018-10-01:88020:88014:8:3.8 I want to create a script that, in each line, checks the second column (in this case, in both cases it ...
0
votes
1answer
28 views

one-liner to delete a part of a column with matching pattern (sed/awk etc)

A very generic question but I am looking for the simplest way solve this very quickly and efficiently I have a file with a very large number of lines which looks like this 451267 sample1.txt ...
0
votes
2answers
873 views

Cut command Error: the delimiter must be a single character

I am trying the following command on bash-4.3 $history | grep history | xargs cut -d ' ' -f1 but i am getting the following delimiter Error that I can't get rid of cut: the delimiter must be a ...
2
votes
2answers
131 views

How to cut the last 5 strings in one particular column for all rows

I have a file with multiple columns and rows, and I need to cut the last 5 strings of my third column and print it in an extra column. For example: 1 info1 AAAAAAAAAAA 2 info23 TTTTTTTTTT 3 ingo45 ...
5
votes
4answers
9k views

cut / grep and df -h

How can I grep or cut the "173G" under "Verf"? I need this for Unix scripting in school. jonas@jonaspc:~/$ df -h /dev/sda2 Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf /dev/sda2 ...
0
votes
2answers
331 views

Ambiguous redirect for stdin to while loop [closed]

I would like to run a command for each entry in a column of a file. I am currently doing the following, but am getting an ambiguous redirect error. while read -r entry; do cmd "$entry" ; done < $...
54
votes
7answers
215k views

Split string by delimiter and get N-th element

I have a string: one_two_three_four_five I need to save in a variable A value two and in variable B value fourfrom the above string
0
votes
0answers
57 views

Split Logs into different files - BASH/LINUX [duplicate]

I want to do the following for my official assignment. I have a user.log file with mammoth amount of logs, I need to cut down that file into small files. Requirements are as follows: Main User.log ...