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

learn more… | top users | synonyms

0
votes
1answer
41 views

Using cut command for an environment variable

I want to extract the host name of a machine and omit whatever exists after .. For example, the command hostname says compute-0-0.local. So, I used `cut command like this # hostname | cut -f 1 -d "." ...
0
votes
2answers
1k 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/...
0
votes
2answers
65 views

deleting lines between rows in a text file using awk or sed

I am wondering if there is a sed or awk command to delete all lines between the 'Query_' headers in column 1, if the number of lines between each header is less than 5. The following is an extract ...
3
votes
2answers
158 views

`cut`: selecting columns containing a string

I have a big file with several columns on each line. I'm familiar with using cut -f -d to select specific columns by their number. I checked the manual for cut and it doesn't seem that there's a way ...
0
votes
1answer
47 views

How can I remove duplicate entries in linux log

I've turned mysql general log on and I've been logging every transaction that occurs for the last week. I also have a cronjob running every 5 minutes doing some mysql transactions which is polluting ...
2
votes
2answers
46 views

Get only the size of a mounted filesystem

I want to get only the total size of a mounted filesystem. But the catch is that I only know about the mount point. So, I thought of using the df command. To get the size of this mounted filesystem, ...
1
vote
2answers
32 views

Generating strings of words with space delimiters from cut statement

I am new to bash. When I run the following command: grep "type" /root/myFile | cut-d'=' -f2 I get the following: 102 304 503 442 I want to store the contents of the first command into a ...
1
vote
2answers
1k views

Keep newlines in output of cut

Let's imagine we have a file: foo bar foo1 bar1 I want to cut every second word in every line, so I want file to look like this: foo foo1 I am trying to use cut -d ' ' -f -1 but what I get is: ...
3
votes
3answers
42 views

awk to cut portion of a field and still print entire line

I have this line: 08:30:02.480507 IP 192.168.100.150.65119 > 192.168.100.151:53 59865 [1au] A? click.em.redbox.com. (48) I need to cut out the ".480507" in the timestamp so the line looks like ...
29
votes
4answers
43k 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? ...
1
vote
3answers
64 views

How can I use a triple slash as a delimiter with cut?

I have a table in which each entry looks something like, coagulation factor VIII-associated 1 /// coagulation factor VIII-associated 2 /// coagulation factor VIII-associated 3 I would like to use ...
0
votes
2answers
37 views

Extract the second quoted string in a line of output

I have a line of output with three quotes, and I specifically need to extract the second quote into a variable. So for example, with the command cmd | grep tokens, I get the following output: Output ...
1
vote
4answers
42 views

cut column 2 from text file

My text file has no delimiter to specify separator just spaces, how do I cut out column 2 to output file, 39 207 City and County of San Francisc REJECTED MAT = 0 78 412 Cases and ...
14
votes
9answers
38k views

A command to print only last 3 characters of a string

I know that the cut command can print the first n characters of a string but how to select the last n characters? If I have a string with a variable number of characters, how can I print only the ...
1
vote
1answer
36 views

changing a specific 'column' inside a txt file

I have a file with thousands of entries like this: 6/05/2016,32,34,40,45,48,,01,10 10/05/2016,02,26,27,40,49,,05,10 13/05/2016,07,15,28,31,42,,10,11 17/05/2016,15,27,32,36,39,,03,10 I want to ...
3
votes
1answer
45 views

Modify values in a column based on number of colons it contains

I would manipulate the contents of the second column based on the number of colons it contains. If the second field contains more than one colon then I would require the content before first colon ...
0
votes
2answers
84 views

cut -c won't work on my .sh file [closed]

I have tried the following commands cut -c-11 ifshell.sh cat ifshell.sh | cut -c-11 ifshell.sh cat ifshell.sh | awk '{print $1} | cut -c-11 ifshell.sh But every time I get the full contents of ...
1
vote
2answers
42 views

cut out specific fields from text file [duplicate]

I have a text file with 9 fields separated by : survey:m1111771::rent:travel:::Morning: How do I pull field 1 and 8 only to a separate file for example it would look like this, survey:Morning
0
votes
1answer
36 views

Recursive Directory search, Showing most recent file in folder

Can someone point out where am going wrong please. Am doing a directory search (Based on the folder structure and file type) The folder structure is the same for every customer. Just the customer ...
1
vote
4answers
62 views

Using cut to return the middle of a string

I have an xml string echoed to stdout along the lines of <xml:attribute>{41c33a-4893b-3627a-617a}</xml:attribute> I want to return the string {41c33a-4893b-3627a-617a} in this case. I ...
16
votes
5answers
8k views

What constitutes a 'field' for the cut command?

For example, the cut command can take a parameter -f, which according to man select only these fields; also print any line that contains no delimiter character, unless the -s ...
3
votes
2answers
48 views

pipe process output to command split by line and whitespace

On the system I'm using I often need to cancel jobs I run. I can check my jobs like this: $ showq|grep jquick 2001744 jquick Running 120 00:08:26 Mon Apr 11 11:06:02 2002020 ...
0
votes
0answers
17 views

Dictionary - synonyms

I have czech czech-finnish dictionary and I have two czech synonyms in one row. Example: záchod (m); toaleta (f) WC; käymälä; miestenhuone; naistenhuone; vessa Synonyms are divided by semicolon ...
-1
votes
3answers
60 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 ...
1
vote
1answer
159 views

I need to merge multiple .csv files together side by side with unequal number of rows

I have anywhere from 3-5 .csv files and need to be able to merge them together while keeping everything in its respective columns below is an easy example with files with varying number of rows. file1 ...
3
votes
3answers
48 views

Strings - Extract File Version Recursive

I have been using strings to extract and compare file versions between directories. I don't seem to be able to do this recursively. The method I have been using per file is: strings -e l ...
2
votes
5answers
123 views

how to cut fields of a directory name?

I have directory named 140905_M01771_0112_000000000-ABBYT. I want to get the third field i.e. 0112. I tried: cut -d _ -f 3 131230_M01771_0032_000000000-A7874 giving me error: cut: ...
2
votes
5answers
2k views

How let `sort | uniq -c` separate the number of occurrences by a tab charactor?

uniq -c separate the occurrence number by spaces, which is hard for to cut or awk to separate it out later. 1000_A1\tB1\n ___1_A2\tB2\n I can solve this problem using sed -r 's/^ *([0-9]+)/\1\t/' ...
0
votes
2answers
108 views

Using Both Grep and Cut

I want to grep the output of tcpdump and cut some part of it but the command below is not working. tcpdump ... | grep -i --line-buffered "..." | cut -d'&' -f1,2 Do you know what is the problem? ...
1
vote
2answers
59 views

how to store output of echo and cut to a variable

I have a file named test which has two columns one having ID and other having status. I want to loop through the file and print IDs where status have one particular value (e.g. 'ACTIVE'). I tried ...
1
vote
1answer
110 views

cut column range sed/awk/cat

I'd like to cut a certain range of text (i.e. characters 17-63) repeatedly from a *.txt file, which is several thousand lines long. One line looks like this: <script>addRow("...
1
vote
3answers
112 views

Using bash variable substitution instead of cut/awk

Can I use bash variable substitution to extract a piece of a variable based on a delimeter? I'm trying to get the immediate directory name of a filename (in this case, foo). $ filename=./foo/bar/baz....
1
vote
1answer
48 views

grep content between two starting bracket

Below is file output that I want to access [1] RsyncCommand: 0 Number of files: 18 Number of files transferred: 0 Total file size: 24.01M bytes Total transferred file size: 0 bytes Literal data: 0 ...
3
votes
5answers
10k views

How to use grep and cut in script to obtain website URLs from an HTML file

I am trying to use grep and cut to extract URLs from an HTML file. The links look like: <a href="http://examplewebsite.com/"> Other websites have .net, .gov, but I assume I could make the cut ...
4
votes
5answers
879 views

How to cut a date/timestamp String?

So I am using TIMESTAMP=$( stat -c "%y" $JARNAME.jar ) print $TIMESTAMP and its output is something like 2015-04-24 17:23:03.000000000 -0500 I need only the 2015-04-24 17:23:03 part
-1
votes
1answer
41 views

cut command behaving differently when its output is “ * ” [duplicate]

I am trying to create a shell script, below is a part of which where i am trying to extract some value from a record in a file: tgt_val=`cat $file_name | grep "$string_name" | cut -d"|" -f$column_no` ...
0
votes
1answer
71 views

bash: How to determine the largest number (newest version) from: ls *.tar.gz | cut -c 2-4

Hi I'm trying to get the largest number (newest version) of a file, I got a bunch of tar.gz files in a directory, versions of some software in the format v${version_number}_software.tar.gz, where ${...
2
votes
2answers
114 views

“cut” hangs when using “tail -f” in combination with “tr”

I'm try to pipe chat log files to some speech output, and want to remove timestamps with cut and remove special characters with tr. Unfortunately, cut seems to halt when using it with tail -f in ...
1
vote
2answers
49 views

How to extract first part of filenames with same suffix?

I want to get at the prefix of a variable-length filename. In: some_filename_123-uniq.tar.gz Out: some_filename_123 In: some_filename_1-uniq.tar.gz Out: some_filename_1 This does the exact opposite ...
0
votes
1answer
61 views

Strange cut behavior

I'm using cut (GNU coreutils) 8.24. The command: echo "TEST=test" | cut -d"=" -f2- outputs Ttest. I don't think this is the intended behavior. Am I using it wrong or is there something wrong with my ...
2
votes
3answers
65 views

split a file by a character and add it to the data

I have a question that I would like to make simpler, how do I split the second field of a file (space delimited) by an underscore and add the second part as a new field to the data (output as tab)? ...
1
vote
1answer
40 views

Match data from array to data from file?

I'm trying to match up the data from an array the lists the days of the week like this: MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY The files data reads like this: Name1,Tuesday Name2,...
12
votes
2answers
2k views

coreutils that are utf aware?

When I used cut today, I found out it doesn't treat a UTF-8 character as a character, but 3 characters because it's 3 bytes long. This seems to be generally true for many tools. Are there versions ...
6
votes
7answers
282 views

How can I apply `cut` to several files and then `paste` the results?

I often do operations like paste <(cut -d, -f1 file1.csv) <(cut -d, -f1 file2.csv) which is very tedious with more than a few files. Can I automate this process, e.g. with globbing? I can ...
0
votes
1answer
52 views

How to find number of unique 'applications' in Debian jessie

This is a follow-up query on allpackages.txt.gz has two different file-sizes? $ wc -l allpackages.txt 57725 allpackages.txt I looked at the output and it says 57725 -6 the header files which is ...
3
votes
4answers
2k views

How to cut everything until a specific word / after a find in a script

I am trying to get the output of files from today which contain "ERROR". I use this to find the files I want: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gandalf_*"\ -daystart -...
1
vote
6answers
159 views

string manipulation without awk or sed

any help on this problem is appreciated I have a text file with the following format We can safely assume that the names are always three characters long, profession 7 characters and salary 5 ...
1
vote
2answers
263 views

how to do inverse cut?

I am sill new in this. I would like to ask, how to inverse the cut? Example; ./24feb/frfr I want after cut command, the result will be ./feb/frfr. How to do it?
0
votes
2answers
5k views

cut string on last delimiter

I have a filename like a.b.c.txt, I want this string to be split as string1=a.b.c string2=txt Basically I want to split filename and its extension. I used cut but it splits as a,b,c and txt. I ...
2
votes
1answer
185 views

Cut command does not separate by tab in script

Note : I don't know how to insert tabulation in my text, I replaced it by [tab] I have a list file name value separated by a tabulation : host1[tab]ip1 host2[tab]ip2 host3[tab]ip3 host4[tab]ip4 ...