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
vote
3answers
1k views

Printing Characters after a Colon

How do I print anything after the colon? Input: color:white,name:green so I would like to print anything after : Output: white,green
5
votes
7answers
8k views

grep first n and last n characters from a line in a file

I have a log file which looks like: Mar 23 08:20:23 New file got created in sec: 235 Mar 23 08:21:45 New file got created in sec: 127 Mar 23 08:22:34 New file got created in sec: 875 Mar 23 08:25:46 ...
0
votes
2answers
25 views

bash - split by single character and match found items by string

tl;dr: Considering following input, which is some kind of a "list" of devices from nodes, I want to get the IP addresses, but only from devices named 'router.' (not router1., nor gw. or others): gw....
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 ...
30
votes
3answers
62k views

How to cut (select) a field from text line counting from the end?

I know how to select a field from a line using the cut command. For instance, given the following data: a,b,c,d,e f,g,h,i,j k,l,m,n,o This command: cut -d, -f2 # returns the second field of the ...
0
votes
2answers
40 views

Use grep command to read a file from specific line number to end of file

Suppose I have a file which is getting appended in every seconds/minutes. At first time I have read whole file and stored the last line number(eg: last_line_numer was : 2000) later I want to read file ...
0
votes
1answer
23 views

Extract some portion from line with regular expression

I have file which consist lines like : 50.57.61.8 - - [04/Apr/2019:09:52:01 -0400] "GET /tracker.php?q=1&p=2 HTTP/1.1" 302 20 "-" "Rackspace Monitoring/1.1 (https://monitoring.api.rackspacecloud....
2
votes
4answers
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 ...
0
votes
4answers
66 views

shell script - Remove character before a specific pattern

I've my /etc/hosts : #192.168.54.144 name1 #192.168.54.144 name2 192.168.54.143 name3 I would like to remove all character # which is followed by an ip address Ipv4 to obtain that : 192.168....
0
votes
0answers
21 views

Remove unwanted fields in source file itself [duplicate]

I have file like below with four fields separated by space.I want to keep only field1 in the input_file. With awk '{print $1}' input_file > output_file we can extract the required field and re-...
2
votes
1answer
72 views

Remove deduplicates in a very large file()

In this given input file, there are 4 columns. We have to remove the duplicates but there is a catch. There is a preference order C2>C3>C4. so in the output there is only one row with a, one row with ...
-1
votes
3answers
48 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 ...
3
votes
1answer
2k views

Can't redirect cut output

When I try to redirect the output of cut it always seems to be empty. If don't redirect it, the output shows in terminal as expected. This is true for OS X 10.10 and Linux 4.1.6. This works: root@...
0
votes
2answers
30 views

Show line numbers of a file after “cut -d ”;“ -f3 |uniq -d”

I am trying to make a simple command that can show me the duplicate data from one specific column and also give me the original line number. Example of file: JENNIE;30;DOCTOR;F SARA;26;POLICE;F ...
0
votes
7answers
102 views

How to delete the first word in each line of a file?

consider a file names 'file.txt'. It contains the following. dove is a bird tiger is an animal cricket is a game. Expected output: is a bird is an animal is a game.
0
votes
4answers
85 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 ...
0
votes
3answers
84 views

Remove last digit 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's a digit, so the output should be as below: SCDE SF STR1D SREDF2 ...
1
vote
4answers
97 views

Remove a specific portion of line

I have a csv file that has many lines of timestamps in following format HH:MM:SS:MS For example: 00.00.07.38 00.00.08.13 00.00.08.88 The hour is not relevant to me so I would like to cut it ...
2
votes
3answers
191 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 &...
64
votes
5answers
151k 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
168 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/...
-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 ...
200
votes
4answers
272k 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?
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 (...
-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
83 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 ...
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
4answers
178 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
58 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
72 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:...
2
votes
3answers
353 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
88 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
42 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
90 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
58 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
103 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
891 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
94 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
185 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
145 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, ...