Questions tagged [cut]

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

2
votes
4answers
30 views

how to cut first 3 folders from this echo “/home/test/var/opt” ? i need the result “/home/test/var”

How to cut first 3 folders from a string? For example: echo "/home/source/Oracle/test" |cut -d'/' -f4 gives only one folder name, but I need up to the 3rd folder, like below: echo "/home/test/...
0
votes
2answers
18 views

Group items from column using awk

Trying to do the following, I have txt file which as the data of the interfaces. Eth1/15 desc01 1 Eth101/1/11 desc01 1 Eth101/1/16 desc01 1 Eth103/1/21 desc01 1 Eth1/2 ...
1
vote
3answers
61 views

I want to know which word is duplicated on a line and how many times it appears in a file

example: I have file a.txt that contains the following: aunt bear bear true I also have a file b.txt that contains the following: tru tru high the end result I want is : for a.txt : bear x 2 for ...
-1
votes
3answers
75 views

How to print first two fields in a file?

I have a file with country names and then the mobile country code prefix for that country like this: United Kingdom +44 ...more fields United States Virgin Islands +1 ...more fields I need to ...
0
votes
1answer
49 views

What '\t' mean with 'tab' delimiter with 'cut' in BASH [duplicate]

in this command : cut -f2 -d$'\t' ('\t') what is it mean ? i saw it another question, i got the idea about 'tap' delimiter but still want to know '\t' shortcut or sign or command for something How ...
0
votes
2answers
31 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
2answers
45 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....
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
78 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 ...
0
votes
4answers
68 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
2answers
37 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
261 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.
-1
votes
3answers
57 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
201 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 ...
3
votes
4answers
205 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
3answers
106 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
3answers
64 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
4answers
209 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
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=...
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
86 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 ...
2
votes
3answers
476 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
125 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.
0
votes
1answer
74 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 ...
0
votes
3answers
35 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
200 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
210 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
490 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
2answers
203 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:...
2
votes
4answers
478 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 | ...
0
votes
2answers
36 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
29 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
1k 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 ...
1
vote
2answers
413 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 < $...
0
votes
2answers
55 views

How does the f argument work in this example of the cut command?

I'm studying for the LPIC-1 exam and I'm stuck understanding the following example of the command cut: ifconfig enp3s0f2 produces the following result: enp3s0f2: flags=4099<UP,BROADCAST,MULTICAST&...
2
votes
5answers
1k views

awk: split column, print left side of delimiter and paste in the middle of csv

Input file: AAA, BBB:XXX, CCC, DDD, EEE, FFF, GGG, HHH Output should be: AAA, BBB, BBB:XXX, CCC, DDD, EEE, FFF, GGG, HHH I thought about something like: awk -F, '{n=split($2,a,":"); a[n]} {$2=$NF"...
3
votes
4answers
1k views

What does cut return if the specified field does not exist?

I have a string: 6.40.4 and a second one: 6.40 I am using var=$(echo $versionfull | cut -d'.' -f3) to get the third digit from the first string in bash. What does this command return for the ...
1
vote
1answer
55 views

Output log lines between startTime and endTime

Given I have log file app.log with contents: 2018-08-29 07:43:17.123-0500 CDT [osb_02] [[ACTIVE] ExecuteThread: '14' for queue: 'weblogic.kernel.Default (self-tuning)'] INFO - [OSB Tracing] Outbound ...
4
votes
4answers
440 views

How to create a new file with required columns from different multiple files in linux?

I have a directory ballgown, in which there are around 1000 subdirectories as sample names. Each subdirectory has a file t_data.ctab. The filename is the same in all subdirectories. ballgown |...
1
vote
2answers
982 views

Using cut and sed command at the same time in a script

I have the following code in a Bash script: #!/bin/bash # gives summary of my buyings in the report.txt file echo Here is the summary of your purchases: echo ========================================...
0
votes
2answers
80 views

Delete last characters before delimiter

The Input file content is like: header;header;header;header 2018/06/04;141000;bla;bla Desired Output: header;header;header;header 2018/06/04;1410;bla;bla I have the command below with sed sed -i ...
1
vote
4answers
47 views

Need to extract part of string using shell [duplicate]

I have a script like, #/bin/bash -x LASTBUILD=' 174254491 2018-08-08T11:04:40Z gs://abc/kishor/5.4.0.61/xyz-5.4.0-61.tgz TOTAL: 46 objects, 7325896651 bytes (6.82 GiB)' echo "this is the ...
1
vote
2answers
124 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 ...
1
vote
2answers
107 views

How to format a file's last 3 columns starting at the 30th tab or 88th space

Ubuntu 16.04 GNU bash, version 4.4.0 I would like to format this text file filed with zip codes containing 1,264,524 lines. #!/bin/bash wget http://download.geonames.org/export/zip/allCountries....
4
votes
2answers
194 views

Getting the last lines that matches a pattern in multiple files

I have an application that outputs a set of log files to a central directory like this: /tmp/experiment/log/ ├── node01.log ├── node02.log ├── node03.log ├── node04.log ├── node05.log ├── node06....
1
vote
3answers
571 views

Delete a part of a line with sed?

I have the next output: Date Time: June 22 12:40:00 Product User Host IP Software User User *.***.***.*** Software1 User User *.***.***.*** I tried some functions with sed and awk, but is not ...
1
vote
3answers
3k views

How to print specific lines of a text file with cut

I have the next fragment of the output of a log: Server Server: Server Date and Time: June 04 2018 14:10:00 -- Product Version User Host IP Duration ...