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
25 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 ...
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
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 ...
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 ...
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
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
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
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=...
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
254 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.
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 ...
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
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:...
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 | ...
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
874 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
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 < $...
0
votes
2answers
52 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
31 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
706 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
46 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
341 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
580 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
72 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
45 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
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 ...
1
vote
2answers
105 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
173 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
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 ...
1
vote
3answers
389 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
2k 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
354 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
2k 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
164 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
38 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
113 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
363 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
52 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
144 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
41 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
3answers
109 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....