cut

Get free disk space with df to just display free space in kb?

寵の児 提交于 2019-11-27 12:51:43
问题 I'm trying to output the amount of free disk space on the filesystem /example . If I run the command df -k /example I can get good information about available disk space in kb but only by being human and actually looking at it. I need to take this data and use it somewhere else in my shell script. I initially thought about using cut but then my script wont be portable to other disks as free disk space will vary and cut will not produce accurate results. How can I get output of just the free

Using cut command to remove multiple columns

ⅰ亾dé卋堺 提交于 2019-11-27 10:51:09
given input echo 1,2,3,4,5,6,7,8,9,...100 If I want to cut columns 5 I can do cut -d, -f-4,6- what if I want to cut multiple non consecutive columns like 5, 7,etc is there a one liner? newfurniturey You should be able to continue the sequences directly in your existing -f specification. To skip both 5 and 7, try: cut -d, -f-4,6-6,8- As you're skipping a single sequential column, this can also be written as: cut -d, -f-4,6,8- To keep it going, if you wanted to skip 5, 7, and 11, you would use: cut -d, -f-4,6-6,8-10,12- To put it into a more-clear perspective, it is easier to visualize when you

use space as a delimiter with cut command

我怕爱的太早我们不能终老 提交于 2019-11-27 10:09:43
I want to use space as a delimiter with the cut command. What syntax can I use for this? cut -d ' ' -f 2 Where 2 is the field number of the space-delimited field you want. Usually if you use space as delimiter, you want to treat multiple spaces as one, because you parse the output of a command aligning some columns with spaces. (and the google search for that lead me here) In this case a single cut command is not sufficient, and you need to use: tr -s ' ' | cut -d ' ' -f 2 Or awk '{print $2}' mklement0 To complement the existing, helpful answers; tip of the hat to QZ Support for encouraging me

rearrange columns using awk or cut command

强颜欢笑 提交于 2019-11-27 08:32:12
问题 I have large file with 1000 columns. I want to rearrange so that last column should be the 3rd column. FOr this i have used, cut -f1-2,1000,3- file > out.txt But this does not change the order. Could anyone help using cut or awk? Also, I want to rearrange columns 10 and 11 as shown below: Example: 1 10 11 2 3 4 5 6 7 8 9 12 13 14 15 16 17 18 19 20 回答1: try this awk one-liner: awk '{$3=$NF OFS $3;$NF=""}7' file this is moving the last col to the 3rd col. if you have 1000, then it does it with

Print Field 'N' to End of Line

半腔热情 提交于 2019-11-27 08:18:42
问题 I would like to have help or direction on a problem I have in awk. I have a tab-delimited file with more than 5 fields. I want to output the fields excluding the first 5 fields. Could you please tell how to write an awk script to accomplish this task? Best, jianfeng.mao Do Note the following kind comment: There are many fields in my files. Different lines have a different number of fields. The number of fields per line is not standard. 回答1: I agree with matchew's suggestion to use cut : it's

Error using t.test() in R - not enough 'y' observations

一个人想着一个人 提交于 2019-11-27 08:05:42
问题 I got this error for my code Error in t.test.default(dat$Value, x[[i]][[2]]) : not enough 'y' observations I think the reason I got this error is because I'm doing a t.test for data that only has one value (so there wouldnt be a mean or an sd) vs data that has 20 values..is there a way I can get around this.. is there a way I can ignore the data that doesn't have enough y observations??? like an if loop might work...pls help So my code that does the t.test is t<- lapply(1:length(x), function

swift: how to delete part of audio?

。_饼干妹妹 提交于 2019-11-27 07:24:18
问题 I'm creating a simple audio editing tool to trim and delete from an audio. I implemented the trim function and it is working fine. However I searched and tried to implement the delete function and here is my code: func deleteExportAsset(_ asset: AVAsset, fileName: String, completeAudioTime: CGFloat) -> URL { print("\(#function)") let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] let trimmedSoundFileURL = documentsDirectory

How to find the last field using 'cut'

余生长醉 提交于 2019-11-27 05:52:18
Without using sed or awk , only cut , how do I get the last field when the number of fields are unknown or change with every line? zedfoxus You could try something like this: echo 'maps.google.com' | rev | cut -d'.' -f 1 | rev Explanation maps.google.com's reverse will be moc.elgoog.spam cut uses dot as the delimiter and chooses the first field, which is moc lastly, we reverse it again (thanks for the reminder, @tom) to get com Use a parameter expansion. This is much more efficient than any kind of external command, cut (or grep ) included. data=foo,bar,baz,qux last=${data##*,} See BashFAQ

How to strip out all of the links of an HTML file in Bash or grep or batch and store them in a text file

回眸只為那壹抹淺笑 提交于 2019-11-27 04:20:09
问题 I have a file that is HTML, and it has about 150 anchor tags. I need only the links from these tags, AKA, <a href="*http://www.google.com*"></a> . I want to get only the http://www.google.com part. When I run a grep, cat website.htm | grep -E '<a href=".*">' > links.txt this returns the entire line to me that it found on not the link I want, so I tried using a cut command: cat drawspace.txt | grep -E '<a href=".*">' | cut -d’”’ --output-delimiter=$'\n' > links.txt Except that it is wrong, and

How do you parse a filename in bash?

天涯浪子 提交于 2019-11-27 02:32:02
问题 I have a filename in a format like: system-source-yyyymmdd.dat I'd like to be able to parse out the different bits of the filename using the "-" as a delimiter. 回答1: You can use the cut command to get at each of the 3 'fields', e.g.: $ echo "system-source-yyyymmdd.dat" | cut -d'-' -f2 source "-d" specifies the delimiter, "-f" specifies the number of the field you require 回答2: A nice and elegant (in my mind :-) using only built-ins is to put it into an array var='system-source-yyyymmdd.dat'