Hot answers tagged

13

Another POSIX one: awk -F , 'NF == 11' <file If the line has 10 commas, then there will be 11 fields in this line. So we simply make awk use , as the field delimiter. If the number of fields is 11, the condition NF == 11 is true, awk then performs the default action print $0.


8

Using egrep (or grep -E in POSIX): egrep "^([^,]*,){10}[^,]*$" file.csv This filters out anything not containing 10 commas: it matches full lines (^ at the start and $ at the end), containing exactly ten repetitions ({10}) of the sequence "any number of characters except ',', followed by a single ','" (([^,]*,)), followed again by any number of characters ...


7

To select only the SSE flags, try: awk '/SSE/' ORS=' ' RS=' ' The key thing here is setting the record separators on input and output to a space. That way, each option is accepted or rejected separately. For example: $ SUNCC_CXXFLAGS="-D__SSE2__ -D__SSE3__ -D__SSSE3__ -D__SSE4_1__ -D__SSE4_2__ -D__AES__ -D__PCLMUL__ ..." $ newFLAGS="$(echo "$...


5

I'm not sure if you're trying to convert lower to upper or remove lower all together. Give this a shot for the lower to upper conversion. tr [:lower:] [:upper:] < ws2.txt To trim out lowercase chars you can use sed sed -e 's/[a-z]//g' ws2.txt Or you can use tr as suggested by @fd0 tr -d '[:lower:]' < ws2.txt To trim out numbers and capital ...


5

OK, found it myself. The answer is /proc/sys/net/ipv4/conf/*/rp_filter. The option is documented at the Linux Foundation. While this is an old setting, it seems that Ubuntu changed the default value sometime between 07.04 and 14.04. Changing the value from 1 back to 0 fixed my problem.


5

sed -ne's/,//11;t' -e's/,/&/10p' <in >out That first branches out any line with 11 or more commas, and then prints of what remains only those that match 10 commas. Apparently I answered this before... Here's a me-plagiarism from a question looking for exactly 4 occurrences of some pattern: You can target [num]th occurrence of a pattern with ...


4

The simplest grep code that will work: grep -xE '([^,]*,){10}[^,]*' Explanation: -x ensures that the pattern must match the entire line, rather than just part of it. This is important so you don't match lines with more than 10 commas. -E means "extended regex", which makes for less backslash-escaping in your regex. Parentheses are used for grouping, ...


4

Throwing some short python: #!/usr/bin/env python2 with open('file.csv') as f: print '\n'.join(line for line in f if line.count(',') == 10) This will read each line and check if the number of commas in the line is equal to 10 line.count(',') == 10, if so print it will the line.


3

From the mv man page -t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY mv's default behavior is to move everything into the last argument so when xargs executes the command it does it like mv /destinationFolder pipedArgs without the -t it would try to move everything into the last arg piped to xargs. With the -t ...


3

The xmlstarlet tool will do this: xmlstarlet sel -t -m /A -o ID, -v id -n -o C, -v //C -n -o D, -v //D -n test.xml For each A under the root element (-m /A), it prints the string "ID," (-o ID,), the contents of id (-v id), a newline (-n), and likewise for children C (-v //C)and D (-v //D) with their respective headers. The double slashes are the XPath ...


2

And here's a Perl way: perl -F, -ane 'print if $#F==10' The -n causes perl to read its input file line by line and execute the script given by -e on each line. The -a turns on automatic splitting: each input line will be split on the value given by -F (here, a comma) and saved as the array @F. The $#F (or, more generally $#array), is the highest index ...


2

The pstree program seems to be quite nice for this e.g. $ pidof bash | xargs -n 1 pstree -sp init(1)───lightdm(1284)───lightdm(1577)───init(2017)───gnome-terminal(2595)───bash(18001)───man(10946)───pager(10955) init(1)───lightdm(1284)───lightdm(1577)───init(2017)───gnome-terminal(2595)───bash(12895) init(1)───sshd(1181)───sshd(11860)───sshd(11938)───bash(...


1

To filter out either message in one grep, pull in the -E extended regular expression flag (for the "zero or once" meaning of ? below), and the -v inverse match: grep -Ev '^Remote:( Checking segments [[:digit:]]{1,3}\.[[:digit:]]%)?$' which says that the lines should (inverse) match: beginning of line ^ the string Remote: the grouped ( ... ) set of ...


1

Some of what you request could be accomplished with a DNS filter like NxFilter http://alternativeto.net/software/nxfilter/ It could be run on her laptop and point to opendns or Google's dns for the actual requests. It has lots of flexibility around scheduling access to specific domains but I have no idea how you might implement your "voucher" idea. Just be ...


1

If fields can contain commas or newlines your code needs to understand csv. Example (with three columns): $ cat filter.csv a,b,c d,"e,f",g 1,2,3,4 one,two,"three ...continued" $ cat filter.csv | python3 -c 'import sys, csv > csv.writer(sys.stdout).writerows( > row for row in csv.reader(sys.stdin) if len(row) == 3) > ' a,b,c d,"e,f",g one,two,"...



Only top voted, non community-wiki answers of a minimum length are eligible