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

learn more… | top users | synonyms

1
vote
3answers
6 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
434 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
144 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
90 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
100 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
73 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
63 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
14 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
109 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
38 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
71 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" ...
3
votes
3answers
144 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
59 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
356 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
77 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
98 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
260 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. ...
0
votes
6answers
1k 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
77 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
247 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
424 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
578 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
83 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
524 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 ...
3
votes
6answers
224 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
217 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
2k 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 ...
3
votes
1answer
414 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 ...
6
votes
2answers
3k 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 ...
1
vote
2answers
5k 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
6k 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
304 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
398 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
890 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
1k 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 ...
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 ...
3
votes
1answer
212 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 ...
2
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 ...
9
votes
3answers
11k 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
5
votes
3answers
4k 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 ...
2
votes
2answers
256 views

Manipulating and saving multiple files

I have ~2k files that I want to extract 12 of 26 columns and save the extracted information into a new file. I have been doing this for individual files using cat "oldfile.csv" | grep -v "=" | cut ...
2
votes
3answers
795 views

How to cut the output to only gather the filename and get-parameter?

I have multiple files with multiple links that are formatted like this: <a href="http://example.com/fnord.layername.html?parameter=FOO-_-BAR-_-FNORD" class="poit"> <img ... /> ...
1
vote
3answers
873 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/' ...
8
votes
2answers
792 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 ...
3
votes
2answers
363 views

Cut on both characters and field

I have a record like : 2011-05-29 17:51:34 => 'HS|CMGC|RN431|CI13950|CH7-4a37-afe2-acabfc9d262d|DA110529|TI175133|' I want my final output to be something like: 2011-05-29 17:51:34 CI13950 I ...
19
votes
4answers
800 views

What should I use when cut doesn't cut it?

I have a file cities like this: [1598] San Diego, US (inactive) [4517] St Louis, US (inactive) [6346] Orlando, US (inactive) I want to cut out the city names, so that I have: San Diego St Louis ...
1
vote
1answer
636 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
1answer
603 views

Ubuntu 10.10 network connection cut down after few minutes of starting

Ubuntu 10.10 network connection works fine at the start, but few minutes later the network manager pops up a message saying disconnected you are offline and Chrome browser returns an error message ...
6
votes
4answers
3k views

Emacs command to cut OR copy to system clipboard?

As a very new Emacs user, I've been using Ctrl+w and Ctrl+y to cut/copy and paste between buffers in Emacs. Is there a way to do the same thing so that not just Emacs, but the entire system, can have ...
9
votes
3answers
1k views

Can I make `cut` change a file in place?

The man page doesn't give me much hope, but I'm hoping it's an undocumented (and/or GNU-specific) feature.