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

learn more… | top users | synonyms

1
vote
1answer
36 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: ...
1
vote
1answer
32 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 ...
-1
votes
1answer
26 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
3answers
73 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). $ ...
2
votes
2answers
56 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 ...
2
votes
2answers
42 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 ...
2
votes
3answers
58 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)? ...
0
votes
1answer
46 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 ...
1
vote
1answer
37 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 ...
1
vote
6answers
122 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
87 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?
6
votes
7answers
240 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 ...
2
votes
1answer
72 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 ...
3
votes
2answers
94 views

How to split a file by counting digit numbers within a row?

I have a file with 45000 character within each line and I I want to split the original file based on specific numbers of character within a line. as an small example my input file looks like: ...
0
votes
2answers
74 views

Initializing a variable with echo

So, I'm trying to store a part of the name of a file into a variable for other uses. So, if my file was named hello123.txt and I want to store the 123 part. So I try num= echo $file |cut -c6-8 ...
5
votes
4answers
237 views

how to split a file into separate files based on the column headers in original file?

I would like to split a file to different files based on the information in the first line. For example, I have: Input: 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 30 30 30 30 0 2 2 0 2 ...
0
votes
3answers
57 views

Null value than rename file

I have a shell to a task but I should handle the null value in this. So in the task i cut the part of a word and i delete or rename the file, but need another if element for null. For example: I ...
3
votes
3answers
63 views

How do I cut a string already separated by spaces?

Lets say there's a string like this test="1/2/3 4/5/6 7/8/9/0" They are separated by spaces, as well as '/'. I want to return a result like this by taking the second field of each string segment. ...
0
votes
1answer
47 views

Fetch second and fourth column from a file

Problem Statement I am not able to get the values in second and fourth column. Tried grep -i "AUGC\|AACN\|AACY" output.csv | cut -d ',' 2,4 DATA ...
0
votes
2answers
51 views

File size after cut

I am trying to verify if I split large file correctly into multiple pieces. As an toy example, I have a file out_sample: 123456789012 123456789012 123456789012 123456789012 123456789012 This has 64 ...
1
vote
1answer
100 views

Can't redirect cut output

When I try to redirect the output of cut it always seems to be empty. If don't redirect it, the output shows in terminal as expected. This is true for OS X 10.10 and Linux 4.1.6. This works: ...
0
votes
1answer
59 views

bash: cut command produces nothing (just a blank line)

I have a problem with being able to echo a part of a string Here is a simplified version: t=no_1187985:/home/my.name/testing/no I want to echo no_1187985 only so: tt=$(echo $t | cut -d":" -f 1) ...
0
votes
2answers
548 views

Bash to join column from multiple files

I have around 20 files in different folders for which I have created a separate file containing path information called pathtofiles.in; /home/users/gray_wolf/unix/File_1.tsv ...
0
votes
1answer
55 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 ...
0
votes
2answers
974 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 ...
1
vote
3answers
100 views

how to break a line after matching a certain character using shell command?

File1: John Daniel Hommes Cameron;Emily Terry Mussy Barbara Mimi Papu;David Swiss Jen Hans Peter Iril;Kelvin Lilly Gucci Kate Nik;Forum Bill June;Jill and Jack Output file: John Daniel Hommes ...
0
votes
1answer
64 views

How to extract particular fields from lines using shell commands?

File1: 27/07/2014 10.10.03 Breaker1 was closed by Mr. A.Basu Spectrum ui6dms 29/07/2014 04.50.53 Breaker1 was opened by Mr. D.Gupta Spectrum ui6dms and one note added 30/08/2014 03.20.01 EarthSwitch ...
-1
votes
2answers
128 views

select portion of file by line interval [duplicate]

I want to practice using head, uniq and cut, for this data here. I know this thread but it focuses too much on cat and external programs. I would like a simpler answer. I want to take interval from ...
2
votes
1answer
43 views

How can I shorten strings shown in the i3status bar?

I am using the i3status bar. In the bar, I am displaying my wireless network details. However, space is limited and this takes up a whole lot of it. The standard format is defined in the i3status.conf ...
4
votes
5answers
513 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
4
votes
4answers
482 views

How to show only the last k columns in ls -l?

I like to restrict the columns shown in ls -l command, by eliminating the first 4 columns. ls -lh shows: drwxr-sr-x 20 gamma alpha 4.0K May 22 13:18 Desktop drwxr-sr-x 3 gamma alpha 22 Oct 6 ...
2
votes
2answers
150 views

Copy files with parent folder to a new directory

I want to copy some files and include their parent directory in the process. The current structure is similar to: /Module1/A/downloads/m13312/file.pdf /Module1/A/downloads/m17312/file.pdf ...
0
votes
1answer
161 views

Cutting logs (and not copying) from a log file between two time stamps

I have a very huge access.log file of 2 Gb containing apache access logs. The date time format in that is as below : 04/May/2015:02:15:25 I want to cut (and not just copy) the logs from this ...
1
vote
4answers
1k views

What the equivalent of “grep | cut” using sed or awk?

Say I had a config file /etc/emails.conf email1 = user@dinkum.dorg email2 = user@winkum.worg email3 = user@stinkum.storg and I wanted to get email2 I could do a: grep email2 /etc/emails.conf | ...
0
votes
3answers
63 views

Beginner Questions Regarding “<”, “<<”, and reading files

I know that I can do tr a b < file, but how do I do that for ls? So for example, How to feed ls -l a list of files from a 'file'. I tried the below and it did't work. $ cat>test A B C $ ls -l ...
0
votes
3answers
142 views

How to find the word after a given pattern using cut?

I have a file that looks like this: -config1 -config2 param2 -config3 param3a param3b -config4 param4 and I can use the following to extract param2: echo $(<file) | cut -d' ' -f3 However I ...
2
votes
1answer
449 views

How to truncate text lines to N characters maximum? [duplicate]

Given a text file, or the output of a command, how can I truncate it so that every line longer than N characters (usually N=80 in a terminal) gets shorten to N characters maximum?
2
votes
3answers
459 views

how to use awk/cut to get column data which has space

I have data in below format: 16 SQL*Plus vilconv1 dox-conv2 16 TOAD background query session Disha WORKGROUP\AD now I want to ...
2
votes
5answers
5k 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 ...
0
votes
5answers
355 views

Compare one to one lines in 2 different files using shell scripting [closed]

I have two files: File1 File2 abc abc cde cde,xyz,efg,hij,...,n efg lmn,opq,weq,...n Now I want to compare File1 line1 with File2 line1, line2 with line2 and ...
-2
votes
1answer
1k views

How to use Cut and Grep command to find data separated by “:” [duplicate]

In my simple database, it contains text of like, example, soldiers. Name:Rank:Gender:Age:Years of Service Tom Corporal:Recruit:Male:19:2 Nicole Sergeant:Corporal:Female:30:10 Daniel ...
0
votes
1answer
648 views

How to use grep and cut together?

Lets say I'm doing a database for fruits. Using a text file for it, inside contains, in this format, (Fruit:Quantity:Cost) Apple:10:1 Orange:20:2 Pears:10:3 Banana:20:4 10 Apples at $1 each. 20 ...
0
votes
1answer
448 views

Linux cut command with -f1

What is the meaning of the following command: cut -d" " -f1 I found out what cut -d" " means: removing spaces, right? but what means this -f1?
0
votes
2answers
2k views

How can I store each seperate entire line in a text file into an array?

I have a file called "threewords". It contains the information: \#gray speedy bee gr-A | sp-E-d-E | b-E \#gray greedy pea gr-A | gr-E-d-E | p-E When I run the command: cat threewords | grep ^# ...
2
votes
2answers
113 views

Combine output from df -h /dev/xvda1 into a single line

I want to convert the 2 line output from df -h into a single, meaningful line i.e. Take [root@ip-10-42-1-246 tmp]# df -h /dev/xvda1 Filesystem Size Used Avail Use% Mounted on /dev/xvda1 ...
0
votes
2answers
169 views

Grep matching cell of the csv file and index of that row

I have csv file and I want to see numbers that start with 0.99 and their row's index which is the first cell of that row. This is what I have so far: cat fil.csv | grep '0\\.99'| tee > (cut -d, ...
4
votes
6answers
12k views

get first X characters from the cat command?

I have a text file I'm outputting to a variable in my shell script. I only need the first 50 characters however. I've tried using cat ${filename} cut -c1-50 but I'm getting far more than the first ...
1
vote
1answer
1k views

Split very big xml file into little pieces with specific line number count

This is how I did to extract the first 100000 lines from my big xml file (2gb): head source.xml -n 100000 > part.xml How can I keep splitting them to 100000 line (or specific file size chunks) ...
2
votes
1answer
552 views

“Argument list too long” while executing cut and sed in a subshell to set a variable

I have written a bash script with has a python code embedded within it. What I did was read in the file and cut it with the below bash commands and then I exported it so that the python code could use ...
0
votes
2answers
115 views

How to list only filenames removing directories and subdirectories

How can I get the list of only filenames and remove directory and subdirectories using find, sed, awk, cut or any. For e.g : I get list of all media files using find as such: find /var/warehouse/* ...