cut

Is it possible to use a string as a delimiter in unix cut command?

对着背影说爱祢 提交于 2019-12-03 05:05:34
If I want to cut a list of text using a string as a delimiter, is that possible? For example I have a directory where a list of shell scripts call same perl script say abc.pl So when I do $grep abc.pl * in that directory, it gives me following results xyz.sh: abc.pl 1 2 xyz2.sh: abc.pl 2 mno.sh: abc.pl 3 pqr.sh: abc.pl 4 5 I basically want all the output after "abc.pl" (to check what range arguments are being passed to the perl right now) When I tried $grep abc.pl * | cut -d'abc.pl' -f2 OR $grep abc.pl * | cut -d'abc\.pl' -f2 its giving me cut: invalid delimiter When I read man for cut it

How do I cut letter X out of a word?

好久不见. 提交于 2019-12-02 20:33:30
问题 I need to cut letter X out of a word: For example: I need to cut the first letter out of Star Wars, the fourth out of munich,... 1 star wars 4 munich 5 casino royale 7 the fast and the furious 52 a fish called wanda to tar wars munch casio royale the fat and the furious a fish called wanda I already tried it with cut, but it didn't work. This was my command: sed 's/^\([0-9]*\) \(.*\)/ echo \2 | cut -c \1/' So it gave me this output: echo star wars | cut -c 5 echo munich | cut -c 5 echo casino

bash script use cut command at variable and store result at another variable

混江龙づ霸主 提交于 2019-12-02 20:26:23
I have a config.txt file with IP addresses as content like this 10.10.10.1:80 10.10.10.13:8080 10.10.10.11:443 10.10.10.12:80 I want to ping every ip address in that file #!/bin/bash file=config.txt for line in `cat $file` do ##this line is not correct, should strip :port and store to ip var ip=$line|cut -d\: -f1 ping $ip done I'm a beginner, sorry for such a question but I couldn't find it out myself. The awk solution is what I would use, but if you want to understand your problems with bash, here is a revised version of your script. #!/bin/bash -vx ##config file with ip addresses like 10.10

Count and sort commands used in history

眉间皱痕 提交于 2019-12-02 19:43:11
问题 I have a text file with bunch of commands, for example: ls -l /bin/bash/ cat file.txt bash cat somethingElse What I have to do is, get the names of commands ( ls , cat , bash ) and count them. I already did this: cut -d' ' -f1 file.txt | tr ' ' '\n' | sort | uniq -c This works almost as I would like to--output is: 1 bash 1 /bin/bash 2 cat 1 ls The only thing is wrong here, it has to IGNORE ABSOLUTE paths, so the output must look like this 2 bash 2 cat 1 cat I was trying with a while loop with

Cut end of multiple videos

隐身守侯 提交于 2019-12-02 17:26:35
问题 I need a script to cut off the last 6 seconds of multiple videos. The videos do all have different length. I can‘t find anything helpful online. Does anyone know how to do that? thx 回答1: A method that uses ffprobe to get the input duration, bc to calculate the desired output duration, and ffmpeg to perform the cutting. This method does not require the inputs to contain an audio stream, but it requires two additional tools ( ffprobe and bc ) instead of just ffmpeg . Your preferred scripting

shell script to extract text from a variable separated by forward slashes

妖精的绣舞 提交于 2019-12-02 15:19:23
问题 I am trying to find a way to to extract text from a variable with words separated by a forward slash. I attempted it using cut , so here's an example: set variable = '/one/two/three/four' Say I just want to extract three from this, I used: cut -d/ -f3 <<<"${variable}" But this seems to not work. Any ideas of what I'm doing wrong? Or is there a way of using AWK to do this? 回答1: You need to remove the spaces before and after to = during string or variable assignment. And tell the cut command to

How do I cut letter X out of a word?

孤者浪人 提交于 2019-12-02 11:24:56
I need to cut letter X out of a word: For example: I need to cut the first letter out of Star Wars, the fourth out of munich,... 1 star wars 4 munich 5 casino royale 7 the fast and the furious 52 a fish called wanda to tar wars munch casio royale the fat and the furious a fish called wanda I already tried it with cut, but it didn't work. This was my command: sed 's/^\([0-9]*\) \(.*\)/ echo \2 | cut -c \1/' So it gave me this output: echo star wars | cut -c 5 echo munich | cut -c 5 echo casino royale | cut -c 5 echo the fast and the furious | cut -c 5 echo a fish called wanda | cut -c 52 And

shell script to extract text from a variable separated by forward slashes

穿精又带淫゛_ 提交于 2019-12-02 11:23:53
I am trying to find a way to to extract text from a variable with words separated by a forward slash. I attempted it using cut , so here's an example: set variable = '/one/two/three/four' Say I just want to extract three from this, I used: cut -d/ -f3 <<<"${variable}" But this seems to not work. Any ideas of what I'm doing wrong? Or is there a way of using AWK to do this? You need to remove the spaces before and after to = during string or variable assignment. And tell the cut command to print the 4th field. $ variable='/one/two/three/four' $ cut -d/ -f4 <<<"${variable}" three With the

How to handle more than multiple sets of data in R programming?

不羁的心 提交于 2019-12-02 11:18:52
Ca data <- cut(data$Time, breaks=seq(0, max(data$Time)+400, 400))  by(data$Oxytocin, cuts, mean) but this would only work for only one person's data....But I have ten people with their own Time and oxytocin data....How would I get their averages simultaneously? Also instead of having this type output : cuts: (0,400] [1] 0.7 ------------------------------------------------------------ cuts: (400,800] [1] 0.805 Is there a way I can get a list of those cuts? Here's a solution using IRanges package. idx assumes your data format is Time , data , Time , data , ... and so on.. So, it creates indices

Count and sort commands used in history

夙愿已清 提交于 2019-12-02 10:08:38
I have a text file with bunch of commands, for example: ls -l /bin/bash/ cat file.txt bash cat somethingElse What I have to do is, get the names of commands ( ls , cat , bash ) and count them. I already did this: cut -d' ' -f1 file.txt | tr ' ' '\n' | sort | uniq -c This works almost as I would like to--output is: 1 bash 1 /bin/bash 2 cat 1 ls The only thing is wrong here, it has to IGNORE ABSOLUTE paths, so the output must look like this 2 bash 2 cat 1 cat I was trying with a while loop with a if statement in it which checks if there is a "/" in a line, but it doesn't seem to work. With awk