cut

Bash: Parse CSV with quotes, commas and newlines

笑着哭i 提交于 2019-12-01 16:39:56
问题 Say I have the following csv file: id,message,time 123,"Sorry, This message has commas and newlines",2016-03-28T20:26:39 456,"It makes the problem non-trivial",2016-03-28T20:26:41 I want to write a bash command that will return only the time column. i.e. time 2016-03-28T20:26:39 2016-03-28T20:26:41 What is the most straight forward way to do this? You can assume the availability of standard unix utils such as awk, gawk, cut, grep, etc. Note the presence of "" which escape , and newline

Perl way of using cut,grep,uniq [closed]

↘锁芯ラ 提交于 2019-12-01 15:31:37
I am running a Perl script inside a Perl script, and the output of the script is something like this # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/angyvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/aqmmgvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/69aqvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/69aavqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW

Perl way of using cut,grep,uniq [closed]

做~自己de王妃 提交于 2019-12-01 13:36:18
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I am running a Perl script inside a Perl script, and the output of the script is something like this # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/angyvqnqth/rmn/cqqqa/newfqq1er/111111111/ty9a1.1.e.1234567891008547.ahqva # aAM axac: cmt /tm9/raaqHRW /myqq1fqq1er/aqmmgvqnqth/rmn/cqqqa

Remove the middle n characters from lines in Bash

ε祈祈猫儿з 提交于 2019-12-01 07:32:11
I am trying to cut out the middle of each line in a file. All the lines are like this: 79.472850 97 SILENCE and I need to end up with: 79.472850 SILENCE As each line has the undesired portion starting at character ten and ending at character 14, I was trying to use sed in this way: sed "s/\(.\{9\}\).\{6\}//" but I just end up with everything after character 14. The numbers following the tab space change in every file. What can I do to make sed just cut out the tab and two digits? Thanks for your help. As per your input and expected output, this can be a way: $ echo "79.472850 97 SILENCE" | tr

Remove the middle n characters from lines in Bash

点点圈 提交于 2019-12-01 05:17:07
问题 I am trying to cut out the middle of each line in a file. All the lines are like this: 79.472850 97 SILENCE and I need to end up with: 79.472850 SILENCE As each line has the undesired portion starting at character ten and ending at character 14, I was trying to use sed in this way: sed "s/\(.\{9\}\).\{6\}//" but I just end up with everything after character 14. The numbers following the tab space change in every file. What can I do to make sed just cut out the tab and two digits? Thanks for

Get the 4th Wednesday of each November in R

南笙酒味 提交于 2019-12-01 00:05:10
I have a time-indexed matrix (xts object) and I want only the fourth Wednesday of every November. require(quantmod) getSymbols("^GSPC", from="1900-01-01") #returns GSPC GSPC$WED <- weekdays(time(GSPC)) == "Wednesday" GSPC$NOV <- months(time(GSPC)) == "November" G <- GSPC[GSPC$WED==1 & GSPC$NOV==1] That's as far as I got in R. To solve my problem I punted up to bash. write.zoo(G, "wen_in_nov") I did the following hack: cat wen_in_nov | grep -v IND | cut -c 1-10 | sed 's/-/ /g' | awk '{if($3 >= 22 && $3 < 29) print $1, $2, $3, "winner"}' | sed 's/ /-/g' > fourth_wen The fourth_wen file needs to

How to truncate STDIN line length?

廉价感情. 提交于 2019-11-30 20:14:27
I've been parsing through some log files and I've found that some of the lines are too long to display on one line so Terminal.app kindly wraps them onto the next line. However, I've been looking for a way to truncate a line after a certain number of characters so that Terminal doesn't wrap, making it much easier to spot patterns. I wrote a small Perl script to do this: #!/usr/bin/perl die("need max length\n") unless $#ARGV == 0; while (<STDIN>) { $_ = substr($_, 0, $ARGV[0]); chomp($_); print "$_\n"; } But I have a feeling that this functionality is probably built into some other tools (sed?)

Windows command for cutting columns from a text

时光总嘲笑我的痴心妄想 提交于 2019-11-30 19:43:31
The following content is stored in a file: chrome.exe 512 Console 0 73,780 K chrome.exe 800 Console 0 11,052 K chrome.exe 1488 Console 0 92,720 K chrome.exe 1600 Console 0 32,344 K chrome.exe 2240 Console 0 35,132 K chrome.exe 2360 Console 0 21,276 K chrome.exe 3524 Console 0 66,732 K chrome.exe 3924 Console 0 23,524 K Is there a way to extract the 5th column with the Windows command line? Something like the UNIX cut command. for /f "tokens=5 delims= " %i in (file.txt) DO echo %i If you're familiar with the GNU cut utility, you might be better off using the Win32 port: http://gnuwin32

Cut optimisation algorithm

橙三吉。 提交于 2019-11-30 18:57:48
问题 Me and some of my friends at college were assigned a practical task of developing a net application for optimization of cutting rectangular parts from some kind of material. Something like apps in this list, but more simplistic. Basically, I'm interested if there is any source code for this kind of optimization algorithms available on the internet. I'm planning to develop the app using Adobe Flex framework. The programming part will be done in Actionscript 3, ofc. However, I doubt that there

bash method to remove last 4 columns from csv file

会有一股神秘感。 提交于 2019-11-30 18:39:05
Is there a way to use bash to remove the last four columns for some input CSV file? The last four columns can have fields that vary in length from line to line so it is not sufficient to just delete a certain number of characters from the end of each row. Cut can do this if all lines have the same number of fields or awk if you don't. cut -d, -f1-6 # assuming 10 fields Will print out the first 6 fields if you want to control the output seperater use --output-delimiter=string awk -F , -v OFS=, '{ for (i=1;i<=NF-4;i++){ printf $i, }; printf "\n"}' Loops over fields up to th number of fields -4