cut

Parsing the first column of a csv file to a new file

≯℡__Kan透↙ 提交于 2019-12-17 23:26:51
问题 Operating System: OSX Method: From the command line, so using sed, cut, gawk, although preferably no installing modules. Essentially I am trying to take the first column of a csv file and parse it to a new file. Example input file EXAMPLEfoo,60,6 EXAMPLEbar,30,6 EXAMPLE1,60,3 EXAMPLE2,120,6 EXAMPLE3,60,6 EXAMPLE4,30,6 Desire output EXAMPLEfoo EXAMPLEbar EXAMPLE1 EXAMPLE2 EXAMPLE3 EXAMPLE4 So I want the first column. Here is what I have tried so far: awk -F"," '{print $1}' in.csv > out.txt awk

Using cut command to remove multiple columns

醉酒当歌 提交于 2019-12-17 10:18:21
问题 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? 回答1: 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,

How can I remove the extension of a filename in a shell script?

一曲冷凌霜 提交于 2019-12-17 03:23:58
问题 What's wrong with the following code? name='$filename | cut -f1 -d'.'' As is, I get the literal string $filename | cut -f1 -d'.' , but if I remove the quotes I don't get anything. Meanwhile typing "test.exe" | cut -f1 -d'.' in a shell gives me the output I want, test . I already know $filename has been assigned the right value. What I want to do is assign to a variable the filename without the extension. 回答1: You should be using the command substitution syntax $(command) when you want to

Split a vector and summing values

冷暖自知 提交于 2019-12-14 02:17:45
问题 I'm a R newbie. I've got a vector vec <- c(105,29,41,70,77,0,56,49,63,0,105) and i would like to sum values till "0" occurs and then create a vector with such values, such as: vec2 <- c(322,168,105) But i really don't know where to start! Any suggestion? 回答1: Starting with this vector... > vec [1] 105 29 41 70 77 0 56 49 63 0 105 We can compute a logical TRUE/FALSE vector of where the zeroes are: > vec == 0 [1] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE When you add FALSE

Reading a file in a shell script and selecting a section of the line

半城伤御伤魂 提交于 2019-12-13 19:21:18
问题 This is probably pretty basic, I want to read in a occurrence file. Then the program should find all occurrences of "CallTilEdb" in the file Hendelse.logg : CallTilEdb 8 CallCustomer 9 CallTilEdb 4 CustomerChk 10 CustomerChk 15 CallTilEdb 16 and sum up then right column. For this case it would be 8 + 4 + 16, so the output I would want would be 28 . I'm not sure how to do this, and this is as far as I have gotten with vistid.sh : #!/bin/bash declare -t filename=hendelse.logg declare -t

replacement for cut --output-delimiter

百般思念 提交于 2019-12-13 13:00:34
问题 I created a script that was using cut -d',' -f- --output-delimiter=$'\n' to add a newline for each command separated value in RHEL 5, for e.g. [root]# var="hi,hello how,are you,doing" [root]# echo $var hi,hello how,are you,doing [root]# echo $var|cut -d',' -f- --output-delimiter=$'\n' hi hello how are you doing But unfortunately when I run the same command in Solaris 10, it doesn't work at all :( ! bash-3.00# var="hi,hello how,are you,doing" bash-3.00# echo $var hi,hello how,are you,doing

Add '\n' after a specific number of delimiters

醉酒当歌 提交于 2019-12-13 12:39:57
问题 How can I add a \n after each four ; delimiter in a CSV file (with bash)? Input file sample: aaaa;bbbbbb;cccc;ddddd;eeee;ffff;gggg;hhhh;iii;jjjj;kkkk;llll; Output needed : aaaa;bbbbbb;cccc;ddddd eeee;ffff;gggg;hhhh iii;jjjj;kkkk;llll 回答1: Using (GNU) sed : ... | sed -r 's/([^;]*;){4}/&\n/g' [^;]*; matches a sequence of characters that are not semicolons followed by a semicolon. (...){4} matches 4 times the expression inside the parentheses. & in the replacement is the whole match that was

grep values and re-arranging the file

二次信任 提交于 2019-12-13 10:39:04
问题 hi i have a file name test.txt (standard input):8: <property name="ProcedureName" value="abc"/> (standard input):7: <property name="PackageName" value="123abc"/> (standard input):8: <property name="ProcedureName" value="bac"/> (standard input):7: <property name="PackageName" value="bac123"/> (standard input):8: <property name="ProcedureName" value="cde"/> (standard input):7: <property name="PackageName" value="cd123"/> (standard input):8: <property name="ProcedureName" value="b4u"/> (standard

AppleScript: substring to string or format html

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 07:14:46
问题 I'm working on my applescript right now and I'm stuck here.. Lets take this snippet as an example of html code <body><div>Apple don't behave accordingly <a href = "http://apple.com>apple</a></div></body> What I need now is to return the word without the html tags. Either by deleting the bracket with everything in it or maybe there is any other way to reformat html into plain text.. The result should be: Apple don't behave accordingly apple 回答1: How about using textutil? on run -- example (don

Validating unique values of a column in shell

对着背影说爱祢 提交于 2019-12-13 03:17:48
问题 I get an input file vendor.csv which has a column called retailer. I have a predefined list of valid retailer values which are a,b,c. If 'd' comes in the retailer column I will have to take some action , mostly echo it to a log and stop the processing and notify the user. I have done the following so far f1=/stage/Scripts/ecommerce/vendor/final*.csv k=`cut -d, -f1 $f1 |sort -u` echo $k This gives me a b c d The above o/p is not comma seperated I can store the valid values a b c in a file or a