Questions tagged [cut-command]
32 questions
25
votes
4 answers
Is there any way to make the cut command read the last field only?
I have a space seperated string which is output by a command, which I like to pipe to cut, using -fd ' ' to split on spaces. I know I can use -f to display field number , but can I make it display the last field if I don't know the length of…
Arronical
- 20,241
21
votes
5 answers
Cut command with word as delimiter
Is there any cut command to cut based on a word
eg :
171212 16082784 6264 XXX xxxxxxxx Transaction XXXXX abend ABCD. The task has terminated abnormally because of a program check. 16:08:27
I want the output as :
171212 16082784 …
Anony
- 803
21
votes
2 answers
Why is character "£" in a string interpreted strange in the command cut?
I'm developing a bash script and came up with the following strange behaviour!
$ echo £ |cut -c 1
�
The sign £ is passed to the next command cut whose filter is picking one character only.
When I modify the filter in the cut command to pick 2…
Peter Schramm
- 219
12
votes
1 answer
`cut -d: -f5-` prints lines even if they have no colon
Assuming a file named "file" containing the lines:
foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog
If we use the cut command with…
00-Yalo
- 155
10
votes
6 answers
How to remove the first colon ':' from a timestamp?
I am new to programming!!
Can anyone help to remove the : at the first position in a timestamp: :29.06.2019 23:03:17
Presently I am trying to do it using awk/cut commands as shown below:
TDS="$(grep 'Logfile started' process.log | awk '{print…
Manoj Kumar
- 353
9
votes
4 answers
How would you separate fields with multiple spaces and store them in an array?
In my file mytxt:
field1 field2
------ -------
this are numbers 12345
this letters abc def ghi
Let's say I want to store the first field in an array:
i=0
while read line; do
…
zou hai
- 101
3
votes
1 answer
Store in environment variable
I tried storing the contents of a file in an environment variable using one of those commands.
a= cut -f 1 abc.txt
cut -f 1 abc.txt >a
neither works .
So , can anybody help me out?
xeon
- 295
3
votes
2 answers
How to insert filename by changing format to same file?
I have many files. File format is year(4-digit)month(2-digit)day(2-digit)
Sample filenames:
20150101.txt
20150102.txt
Content of sample filenames
00:00:13 -> 001528
I want to extract data as date from filename and then to insert it in the…
chess_freak
- 121
- 1
- 8
2
votes
3 answers
Remove certain fields from a line
I have the following lines in a file:
Modified folders: html/project1/old/dev/vendor/symfony/yaml/Tests/bla.yml
Modified folders: html/port5/.DS_Store
Modified folders: html/trap/dev8/.DS_Store
Modified folders:…
john deo
- 77
- 6
2
votes
0 answers
can't cut/Paste or move file in all my partition even using "sudo nautilus"
I have big problem to use my PC because I can't cut or paste or move all my file and folder in all my partition without system partition of Ubuntu.
I use Ubuntu 17.04.
I tried to search any response and I tried to open from terminal "sudo nautilus"…
Bob Koots
- 21
2
votes
2 answers
How can I cut the mac address out of DHCPDUMP?
I am trying to use dhcpdump to recognize people logging onto my home network and give them a tailor made greeting using a credential file.
I cannot get the mac address out of the results of dhcpdump. The machine I am running the script is not the…
2
votes
0 answers
Add Terminal Cut (Ctrl+k) to GPaste clipboard
I don't know if this is a local bash setting on my part, but when I cut a line within a terminal (or gnu screen) using Ctrl+k, the result isn't copied to GPaste. Instead, the copied text can only be pasted within that terminal. Is there a way to…
mikemtnbikes
- 278
2
votes
1 answer
option delimiter in cut
I want to know if it is possible with the cut option to indicate the delimiter with a line break "\n" or "\t".
Ex: cut -f 1 -d "\t". This line gives me error.
María José
- 21
2
votes
2 answers
How to split string in TSV file
I have TSV file like this:
abc_1
def_2
ghi_3
jkl_4
mno_5
I want to split that in to the:
abc
def
ghi
jkl
mno
and
1
2
3
4
5
How I can get that?
Lulu' Nisrina
- 39
- 7
2
votes
1 answer
cut not outputting anything
I created a script by using the command line initially:
grep -c "Author" reviews_folder/* | cut -d \/ -f 2 | sort -nt':' -k2 | sed 's/.dat:/ /g'
It worked, however I then needed to make it a shell script which allowed the user to enter a directory…
Matthew Evans
- 21
- 1