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

learn more… | top users | synonyms

1
vote
2answers
25 views

Getting the size of parent folders when using find to search for criteria?

I am hunting for a certain regular expression within the filenames and am seeking to return the parent folders with their sizes in a unique fashion. For example, here is the command that I expected ...
3
votes
2answers
523 views

Split log file by time range

I have a log file and would like to cut it into copies of 15min. In the log file the lines start with: dd mmm yyyy hh:mm:ss,xxx e.g. 12 Feb 2013 16:05:02,xxx log text... and the file rotates ...
7
votes
3answers
769 views

What are the exact differences between awk and cut with grep? [closed]

We know that we can get the second column of the line we want from a file using these two techniques: awk '/WORD/ { print $2 }' filename or grep WORD filename| cut -f 2 -d ' ' My questions are: ...
8
votes
3answers
379 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? ...
2
votes
3answers
128 views

Aggregate and group text file in bash

I have a big text file(with 5m lines) in this format(4 columns, separated by ;): string1; string2; string3; userId The first 3 strings (SHA1s) form a single ID, called appId (so it can be ...
2
votes
4answers
89 views

Use `cut` to extract a list from /etc/passwd

How could I use the cut command to extract a list of usernames and login shells from the /etc/passwd file, where the resulting usernames and login shells are separated by a single space? Sort the ...
3
votes
4answers
177 views

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

Hello I try to get the output of files from today wich contains ERROR. I use this to find the files I want: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gandalf_*"\ -daystart -mtime ...
1
vote
2answers
165 views

How to show specific lines from specific columns of a file

First off, I'm not allowed awk, sed or perl. For my assignment I was given a file of employee list: Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles ...
1
vote
2answers
37 views

numfmt invalid suffix input

I am using numfmt to convert a remote file's Content-Length from bytes to IEC format, i.e. 21M $ curl -sI http://jruby.org.s3.amazonaws.com/downloads/1.7.12/jruby-bin-1.7.12.tar.gz|grep Length|cut ...
4
votes
3answers
389 views

Dynamically trim stdout line width in Bash

Lately, I have been experimenting with the ps command, and sometimes long paths wrap to the next line (or two) and make it hard to read. I want to pipe the ps output into another program to limit the ...
1
vote
3answers
210 views

how to pipe the output of cut to the foreach command?

I have the cut command I want that grabs the first word in each line of a file. I then want to put each word from the cut command into a foreach. I then want to do a grep command inside the body of ...
16
votes
5answers
755 views

What constitudes 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
1k views

Range of the command cut in unix

I'm trying to make a shell script, I want to cut a string using the 'cut' unix command, as follows: namecmpaux=$(echo $namecmp |cut -c0-19) But when I run the shell tells me the following error: ...
2
votes
5answers
230 views

Print text between (and including) two delimiters on a line

What's the best way to print the text between (and including) the first pattern ("SELECT" or "SSELECT") and a second pattern ("[") using a command-line took (e.g. cut, sed, awk)? For example, given ...
5
votes
2answers
307 views

ls for cut -f string not working

I have a problem with feeding cut output to ls. This doesn't work: rep="S1_1000,0000-00-00c,0000-00-00d,0000-00-00e" ls tab_yeast/{`echo $rep | cut -f2- -d','`}*.tab.gz ls: cannot access ...
3
votes
2answers
93 views

Command in variable one are affecting output of other variable when displayed together in UNIX

I am having two file naming Extra_info and Class_info Class_info contains data : stuId stuName stuClass S01 jagdeep First S02 harsh First S03 Roop Second S04 Kali Third ...
-1
votes
1answer
450 views

Display column that has a specific string

Content of a sample file is as follow: AA BB CC DD BB 1 2 3 4 9 5 6 7 8 10 I want to display the whole columns that contain BB and DD. In the real case, I do not know which columns contain ...
1
vote
1answer
25 views

selecting a field when you cannot count from the start [duplicate]

I have a long file ( 20000+ lines) where each of the lines is a description of a book: book_number "title of the book" size type author_number Where the element in quotes is a string with quotes ...
5
votes
5answers
163 views

A shell script to write selected fields to a single line

I have a log file trace.log which prints the time stamp, thread name and Transaction method and transaction ID as below. 2014-01-23 15:50:41,724 [catalina-exec-35] INFO TRANSACTION getConnection ...
2
votes
2answers
65 views

How do I use cut to separate by multiple whitespace?

I would like to get the last column of this sample: [ 3] 1.0- 2.0 sec 1.00 MBytes 8.39 Mbits/sec [ 3] 2.0- 3.0 sec 768 KBytes 6.29 Mbits/sec [ 3] 3.0- 4.0 sec 512 KBytes 4.19 Mbits/sec ...
4
votes
2answers
91 views

Cut a string- Catch: There is file with same name as string in the same path

Input /in/archive/ABC/20140111_ABC_018_PART_001.dat Desired Output: 20140111_ABC_018_PART_001.dat Command used: cut -d/ -f4 "/1a/ftproot/archive/ABC/20140111_PR1_018_SALESDOC_ITEM_001.dat" ...
7
votes
2answers
6k views

How to cut (select) a field from text line counting from the end?

I know how to select a field from a line using the cut command. For instance, given the following data: a,b,c,d,e f,g,h,i,j k,l,m,n,o This command: cut -d, -f2 # returns the second field of the ...
3
votes
3answers
519 views

Cut a field in a string with bash

I need to lower all upper-cases of file and folder names from a path, recursively inside other folders found; I need to do that with a bash script. Here my code: for file in $(find $1 -type f) do ...
0
votes
4answers
61 views

cut+sed function joined

Input dir/foo Output dir./ so I need: echo 'dir/foo' | MAGIC Q: What is MAGIC? (something like a cut+sed joined:D)
3
votes
2answers
881 views

Cut command not extracting fields properly in aligned columns

I have a text file in which I must cut the fields 3,4,5 and 8: 219 432 4567 Harrison Joel M 4540 Accountant 09-12-1985 219 433 4587 Mitchell Barbara C 4541 Admin Asst ...
1
vote
2answers
90 views

Split out data from a column

So at the moment I have some input email addresses and would like to separate the alias and the domain, then copy them to the end of the line. For example, from a line that has ...
0
votes
3answers
127 views

ps output differs when run from command line and from script

I have to create list of PID's of the running processes. Here is the script ps echo "fields are " ps | cut -d' ' -f1 ps is showing PID TTY TIME CMD 2168 pts/4 00:00:00 sh 2177 ...
4
votes
1answer
495 views

Does the inverse command of cut exist?

First question, so if the format's not correct, sorry! I like using the cut command in Linux with the -c flag. However, I'm interested in finding a command that sort of does the set inverse of cut. ...
9
votes
7answers
2k views

Combining 2 different cut outputs in a single command?

I have a file such as the following: 1234 ABCD EFGH I'd like to convert it to the following: 2341 BCDA FGHE The actual file has 4,000 words, so I would like to do this in an efficient manner. I ...
1
vote
6answers
3k views

Using cut/awk/sed with two different delimiters

I have the following cases: case@test.com case_1_2@test.com case_1@test.com I'm trying to convert these to case@test.com case@test.com case@test.com So it should remove everything from ...
1
vote
2answers
85 views

How to hide the . and .. from ls

When I run ls -l on a directory, I see an entry titled '.' How can I remove the row containing '.' from the output? ls -latr /foo | tail -n5 -rw-rw-r-- 1 guest bar 59169 Aug 20 12:22 ...
5
votes
2answers
471 views

Unix: how to read line's original content from file

I have a data file, the content is as follows: department: customer service section: A department: marketing section: A department: finance section: A When I read each line, I ...
2
votes
1answer
686 views

Issue with real-time log inspecting piping tail, grep and cut

I have to inspect a growing log in real time, and I found an issue that makes me miss some lines (I can't understand exactly what lines) using tail -f or tailf, grep and cut. I use grep because I ...
1
vote
2answers
770 views

How to cut file name not actual file

I have a list of file names like ./run_results/rat/coding_exons/0.01_100_best.txt ./run_results/mouse/introns/0.01_100_best.txt I want to create new files with names like ...
2
votes
4answers
106 views

find command: how to ignore pathname?

I have to find some type of files in a directory and it's subdirectories and I only have to print out the filenames. So here's the main command: find -type f -name "*.c" Now, how could I cut the ...
0
votes
3answers
670 views

Does delimiter parameter on cut command, always expects it to be in between a string?

I noticed something with the cut command today, which somehow I had never noticed before, even though I have been using and working with them for a long time. From string /users/developer/, I wanted ...
5
votes
3answers
5k views

Search for values in 2 columns from CSV

I have a csv files with say 20 odd columns. I need to get the 14th and 15th column values where value in 14th column is say "VALUE1" and value in 15th column is "VALUE2". My condition gets satisfied ...
4
votes
4answers
2k views

cut / grep and df -h

How can I grep or cut the "173G" under "Verf"? I need this for Unix scripting in school. jonas@jonaspc:~/$ df -h /dev/sda2 Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf /dev/sda2 ...
3
votes
6answers
277 views

cut command, order not preserved?

I have a sample file:- [root@localhost base_filters]# cat shortlist 2233|charles harris |g.m. |sales |12/12/52| 90000 9876|bill johnson |director |production|03/12/50|130000 5678|robert ...
3
votes
2answers
321 views

not getting desired output with cut command?

[root@localhost ~]# ps aux | grep ata root 19 0.0 0.0 0 0 ? S 07:52 0:00 [ata/0] root 20 0.0 0.0 0 0 ? S 07:52 0:00 [ata_aux] root ...
2
votes
4answers
3k views

print last field from line + alternative for awk

Due to technical reason on my Solaris machine, I can't use awk in order to print the last field in line. What are the other alternatives to awk that print the last field from line (using cut or tr ...
1
vote
2answers
6k views

Help understanding cut command in script

In a bash script, there are the following 2 lines: ipaddr=$0 segments=`echo $ipaddr | cut --delimiter=. --fields=2-3 --output-delimiter=/` I do not know how to interpret the second line where the ...
3
votes
3answers
9k views

How to use cut command to get the first and last elements of a row?

I've asked almost the same question already, but this time, I want to retrieve the X latest elements of a row of a CSV file. For example, with an input file as this one: 1;foo;bar;baz;x;y;z ...
2
votes
2answers
454 views

Can you specify an enclosure for cut? [duplicate]

Possible Duplicate: Is there a robust command line tool for processing csv files? I can use cut to extract columns from a file: $ cat foo foo,bar,hello bash,baz,world $ cut -d\, -f2 foo ...
2
votes
3answers
504 views

Regex/pattern matching problem to extract data

What is the best way to remove distances in the following lines and output cdv format. Can this be done reasonably easily on the command line? I'd like to avoid having to write a full-blow script. ...
1
vote
1answer
1k views

Variable Substitution in Awk Print Statement -v

I've spent over an hour poking at this. It can't be this hard... I want to print a column of data from one file to another file. The column I want to print is dependent on what is passed in and stuff ...
2
votes
2answers
2k views

Reorder fields/characters with cut command [duplicate]

Possible Duplicate: Combining 2 different cut outputs in a single command? I have One file - temp.txt - which contains ABCDF PQRST LMNOP I tried this cut command $ cut -c 2-5 temp.txt ...
3
votes
1answer
240 views

Cut colored text ignoring color tags

My problem is similar to this one; I want to use cut to simulate a nowrap on tmux, but my output is colored. I know how many columns I want to keep (50) but I don't know how many color tags will be on ...
8
votes
6answers
235 views

Grab certain contents of a file

So I know tools exist for this problem because I've heard about them, but I don't know what they are. I want to do something like filter out all data but the usernames in /etc/passwd. For example, I ...
14
votes
3answers
17k views

How to cut by tab character

I want to use cut command to break input into fields and get the second field. cut -f2 -d' ' <--- How can I tell it to use tab instead of space