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

learn more… | top users | synonyms

0
votes
2answers
28 views

How do i Reverse output already piped from sort and cut commands

I have to take user input of there UID then use it to reference the /etc/passwd directory and sort the data by first name and display only username,firstname,lastname in that order. The problem i'm ...
1
vote
1answer
27 views

Linux log file structure change for usage with kst

My file (tcp dump from networked sensors) has this shape: 20:06:57.049686 IP (tos 0x0, ttl 64, id 26871, offset 0, flags [DF], proto UDP (17), length 68) e108-193.eduroam.tugraz.ac.at.34225 > ...
5
votes
1answer
28 views

Can not use `cut -c` (`--characters`) with UTF-8?

The command cut has an option -c to work on characters, instead of bytes with the option -b. But that does not seem to work, in en_US.UTF-8 locale: The second byte gives the second ASCII character ...
4
votes
6answers
856 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 ...
0
votes
0answers
16 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 ...
0
votes
1answer
49 views

Cut one line on two [closed]

I want to delete one line on two with linux such that A B C D E becomes A D E how can I make it work?
0
votes
1answer
25 views

Does cut return any fields if separator does not exist

I executed cut -d '~' -f 2 on input RSC AED FCB A~RS and I obtained RSC AED FCB RS I realized that cut will return entire line if the delimiter does not exist. It is that true?
-2
votes
2answers
73 views

Grep and cut the selected field

I am trying to cut the field if a line starts with a particular name, cat $1|while read line do if [ "$1" = "custbills.cmp" ]; then acc_no=`grep "^Custbills" $1 | cut -c29-43` acc_type=`grep ...
3
votes
3answers
245 views

Get the part of a line before the last slash

I'm trying to write a conky script that shows my MPD album art, a 'folder.jpg' in the album folder. My current plan is to use mpc -f %file%, which prints out the file name and path, and then cut out ...
0
votes
0answers
56 views

wget: Retrieving a list of URLs when modifying input data file on the fly

This issue is currently driving me up the wall. It just does not work as it should. I have a file inp with audio samples to download where I preserved the internal ID number by parsing some other ...
1
vote
2answers
42 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 ...
8
votes
3answers
695 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
278 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
138 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
324 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 ...
8
votes
3answers
2k 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: ...
1
vote
2answers
238 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
43 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
589 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
382 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
1k 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
3k 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
329 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
474 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
104 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
1k 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
27 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
179 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
94 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
105 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
1k 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
1k 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
99 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
139 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
648 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. ...
1
vote
6answers
5k 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
88 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
947 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
849 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
865 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
116 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
737 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
307 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
382 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
4k 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
2answers
600 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 ...
8
votes
2answers
7k 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
7k 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
10k 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 ...