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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [cut]

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

1
vote
4answers
30 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 ...
0
votes
2answers
41 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
50 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
163 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
40 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
81 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
90 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
54 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
394 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
50 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
30 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
4answers
84 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
217 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
41 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
61 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
31 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
35 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
58 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
43 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
185 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
47 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
493 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
50 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
30 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
478 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
253 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
62 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
193 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
521 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
64 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
217 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
794 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
125 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
440 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
2
votes
4answers
405 views

Grep and remove lines with a blank field value

I was wondering if there's any command to look for blank field values of a text file and remove the entire line. Example Hello:Its Me Hello:How are you Hello: Hello:Bye And expected output ...
-1
votes
2answers
209 views

Extracting part of line with using awk or sed

neterrore=connectionFailure&u=https%3A//data.com/callback%3Fcode%3DY6mOqlD2Cghcub29IlDKB7KHFuGCemVeoNr1lF5r6_c%26state%3DcDi00NM8gO8BImQwp1G0gmdIznygTwXQ& In this string I need to extract ...
2
votes
2answers
267 views

Parse `uptime` for just the duration

When I run the command "uptime" on my Mac I get this output: 19:52 up 14 mins, 2 users, load averages: 2.95 4.19 4.31 This changes slightly depending on how long the system is up, adding hours and ...
2
votes
1answer
67 views

Cut delimited with unescaped space?

I have a file with text in the format of: User\ Name My\ Password Notice this is actually a 2 column file, where columns contain escaped spaces. cut -d' ' -f2 produces Name but I want to produce My ...
0
votes
1answer
81 views

Why doesn't cut command split a given string?

Cut works as expected here $ cat test 1;2;3;4 $ cut -d ';' -f 2 test 2 $ cut -d ';' -f 3 test 3 But I would expect it to output '21' here, what am I doing wrong? $ updates="" $ echo "$updates" | ...
4
votes
3answers
796 views

how to replace the first element in a CSV with a sequential number?

I have a csv file like this: 5/05/2017;03;07;30;35;43;01;03 9/05/2017;08;12;16;22;26;06;07 12/05/2017;02;20;28;29;44;03;09 16/05/2017;08;11;15;20;30;03;08 19/05/2017;09;11;12;19;30;04;09 23/05/2017;...
0
votes
3answers
57 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" "...
1
vote
1answer
30 views

Shell command to find highest number. But issue is double digit after decimal is not considered highest

Using shell script to find highest number out of the values mentioned in a variable. For example VAR="2011.2/2009.1/2011.10" Shell script should identify 2011.10 is highest of of three Output ...
-1
votes
1answer
100 views

Got command to Filter range of date from particular column of csv but getting failed in one of the scenario [closed]

Got command to Filter range of date from particular column of csv and but it does not work if both start and end date are same and input file has only one entry for that date awk -v start="$start" -v ...
0
votes
0answers
33 views

Cut in sed issue, unknown option to s [duplicate]

echo $HOME $var /home/user abc My variables. echo $HOME$var | sed "s/$(echo $HOME$var | cut -c 3)/ello/g" /hellome/userabc This works as expected. echo $HOME$var | sed "s/$(echo $HOME$var | cut -c ...
0
votes
2answers
425 views

How to filter range of date from a particular column of a csv file?

Consider the input file 1,10/22/2017,Scheduled 2,10/23/2017,Confimred 1,10/24/2017,NA 1,10/29/2017,Scheduled 3,11/1/2017,Scheduled 1,11/2/2017,Scheduled How do I filter date(within range) in 2nd ...
6
votes
5answers
5k views

How do I remove the last characters from a string?

I have a variable set with var='type_cardio_10-11-2017'. I need to remove the last 10 letters from the variable, and append the remaining value to var2. I tried with the following script, but it ...
0
votes
1answer
66 views

Adding delimiter to a string

I am extracting ascii data from network packages captured by tcpdump. I have manipulated the data to the point I am on a single string and now need to cut it. The problem the left over string has the ...
1
vote
2answers
332 views

Delete first 10 characters of every line in textfile

Suppose I have a file, test.java It starts off like this every line /* */ package com.a; /* */ import java.util.List /* */ etc I want to remove the first 10 characters from every line ...
0
votes
2answers
106 views

Counting unique elements in text file

I have a text file containing tweets by users where: 470192 anneJackson Apple's new iPhone is a no go for me 470193 trex90 For something so expensive, I'll go for Android anyway ...