Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
1answer
26 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
151 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:...
3
votes
4answers
58 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
26 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 ...
-1
votes
1answer
24 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
117 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 ...
0
votes
2answers
59 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
34 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&...
0
votes
0answers
28 views

Behavior of cut vs. that of awk [duplicate]

I'm trying to extract the CMD column from a ps -fp <pid> command. Now I know there are several ways to do this, some of which include: $ cat /proc/<pid>/cmdline or $ ps -p <pid>...
2
votes
5answers
63 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
841 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
39 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
127 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
72 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
57 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
38 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
48 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
91 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
168 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....
0
votes
0answers
49 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 ...
1
vote
3answers
92 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
273 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 ...
1
vote
2answers
94 views

How to cut a string based on delimiter which is having space

variable_list=" any:any:-a -b -c any one:one:-c -b -f -m mul mul:one:-c -b -f -m mul " for f in `echo $variable_list` do c1=`echo $f | cut -d':' -f1`; c2=`echo $f | cut -d':' -f2`; c3=`echo $...
4
votes
2answers
741 views

“No such file or directory” when using “-exec” with find

I have a bunch of folders which have a subfolder somewhere called 360. find . -name '360' -type d -exec 'echo "{}"' \; output: find: echo "./workspace/6875538616c6/raw/2850cd9cf25b/360": No such ...
0
votes
2answers
68 views

Git-bash UNIX: Switch columns/fields using cut?

So I have a file with 2 columns as follows: 10 1 11 2 12 3 13 4 14 5 I would like to switch the columns using the cut command. I've used paste <(cut -f2 file.dat) <(cut -f1 ...
0
votes
1answer
31 views

Why does cut not work here as expected with the delimiter?

I have this file as input: root 1243 0.0 0.0 65508 6036 ? Ss Apr30 0:05 /usr/sbin/sshd -D root 7385 0.0 0.1 152932 10644 ? Ss 16:22 0:00 sshd: per1 [priv] per2 ...
-2
votes
3answers
96 views

cut only date and time from given input string— Input string is Cpmplete sting such as 05-09-2018-10.13 [closed]

cut only date and time (i.e.05-09-2018-10.13) from below string /pi_nfs/pixin/axpin-zhgahh/was_logs/was_admin_logs/start_WPS.log.05- 09-2018-10.13:ADMU4000I: Server Node_axpin-...
3
votes
6answers
238 views

How to print the first field which is having the value based on delimeter

File (myfile.txt) contains data as follows: abc#ab1=23 nrt# #clb1aX amd#322 Desired Output: abc nrt clb1ax amd I could do like this, for i in `cat myfile.txt` do s1=`echo $i | cut -d'#' -f1`; ...
0
votes
2answers
45 views

Cut off the first two lines

I'd like to retrive a list excluding the first 2 lines $ pip list Package Version ---------------------------------- --------- alabaster 0.7.10 ...
-1
votes
2answers
108 views

cut command to extract fields

I want to extract date and time from below sequence /hs_nfs/hsfiq/AXZIP-PP567/was_logs/was_admin_logs/start_WPS.log.04-24-2018-08.36.Apr24.zip:ADMU3000I: Server Node_axzip-pp567_AppClusterMember ...
0
votes
2answers
33 views

I can't figure out how to cut this file and find unique words of a particular section

So there's an access log entry file named access_log and I'm supposed to find all of the unique files that were accessed on the web server. access_log is formatted like this, this is just an excerpt: ...
0
votes
0answers
38 views

Comparing two files file1 and file2 with respect to 2 fields in 1st file

I have 3 files: file1: a1/xyza/ref123 a2/xyza/fer123 a3/xyza/yug123 file2: a1/pqra/huj567 a2/pqra/kuf453 a3/pqra/gfc478 file3: a1/*/ref123 a2/*/fer123 a3/*/yug123 a1/*/huj567 a2/*/...
0
votes
3answers
78 views

Cut and replace specific column from a list of file

41703 10002 30003 40002 40000 20203 20203 30100 50000 50000 50000 50000 70700 70600 I have this file. and i Want output as 4.17.3 1.0.2 3.0.3 4.0.2 4.0.0 2.2.3 2.2.3 3.1.0 5.0.0 5.0.0 5.0.0 5.0.0 7....
-1
votes
1answer
46 views

tail and bash: different output when same is expected

I'm trying to sort my logs and found that single digit dates were cut incorrectly. Now I want to either add a 0, or remove the extra space. Prior to that, I wanted to see how to get the correct lines ...
1
vote
1answer
277 views

Extracting “count value” after using “uniq -c”

I'm playing with bash pipelines using a bunch of NBA data. I'm trying to count the frequency of players on the Cleveland Cavaliers, and right now my command looks something like cut -d "," -f 2 ...
-3
votes
1answer
58 views

What does a w | cut -d “ ” -f 1 - with a grep and sort should do?

This is the code I desire to decipher: w | cut -d " " -f 1 - | grep -v USER | sort -u
0
votes
3answers
782 views

cut twice in field

I have a record like 192.168.28.168 user82 [08/May/2010:09:52:52] "GET /NoAuth/js/titlebox-state.js HTTP/1.1" "http://www.example.com/index.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; ...
1
vote
1answer
55 views

zsh yanks only last cut word

I've been using zsh with oh-my-zsh for nearly three years, mostly on debian systems. I'm using ctrlw and ctrly a lot. For three weeks now my workstation is a MacBook and I've been using zsh and oh-my-...
1
vote
1answer
33 views

How to cut specific number without cut all numbers

F gge0006y D 12-30-2006 T 14:05:55 S a69 B 15.3 M gge06001 P 30.6 Q 21.1 R 1006.6 U 1014.6 X 36.1 A 38.994 0 0 G 107.71 0 0 H 8.433 O 36.705 C 7....
1
vote
3answers
40 views

How do I get the first matched substring (of multiple lines)?

I have a file where content looks like /hello="somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff somestuffsomestuffsomestuffsomestuffsomestuffsomestuffsomestuff ...
1
vote
3answers
641 views

How can i compare strings of two files in shell script?

The first field is the username, the second is the password, and the last indicates the action (login/register) File 1: User input hello,world,register File 2: Plain text database admin,123 user,...
0
votes
3answers
588 views

sort Find how many distinct values are among the certain column

For example, this is the list.txt Joe 3 Jack 1 Ulysses 6 Fox 2 Cassidy 1 Jones 6 Kevin 7 Then the output should be 5 because there are 5 different values in the 2rd column. How should I finish ...
0
votes
3answers
63 views

Append n columns together

I have a large dataset, which shows how variable y changes as a function of both space (x) and time (t). There are n columns, each representing one time step. They are tab delimited. note: there are ...
-2
votes
2answers
791 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, but I'm having some trouble getting it. Any help is ...
3
votes
3answers
686 views

How to use Unix Shell to show only the first n columns and last n columns?

I have many csv files. The original design was supposed to have five columns. I just found out that the middle column of the csv file has a string with arbitrary number of commas in it and it is not ...
-1
votes
3answers
75 views

Listing a Summary with limits

I am trying to list a number of offending IP's with a one line command, and am not sure how to do the last little bit, maybe someone can point me in the right direction. cat /var/log/syslog* | grep "...
6
votes
3answers
232 views

Is there a parameter substitution/expansion alternative for “| cut -f1,2,3 -d:” a.k.a. trim after and including n-th character occurence?

An ancient version of ipconfig (inside initramfs) requires its user input to supply only up to 7 colon separated elements, like: ip=client-ip:server-ip:gw-ip:netmask:hostname:device:autoconf result ...
-1
votes
2answers
1k 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. So kindly explain for me your ...
1
vote
2answers
135 views

How to extract text between 2 matching pattern to multiple files?

I have binary file and I want to split it into separate files by START and END patterns. Example of input: yut786y= 3&*%^#$%fsd{'StartOfFile': sdflklfasdgjw723gsdf67asfr55a64 asduf hfna089FUAO ...
1
vote
2answers
564 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