Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

63 votes
9 answers
44401 views
Search only in files that match a pattern with ack
Can ack search only through files that match a specific 'glob' pattern (eg: search for foo in all files named "bar*.c"). The command ack foo "bar*.c" only works in the current directory. Note: I know it's possible with find -exec: find . -name "bar*.c" -type f -exec ack foo {} + But I would like a s...
Can ack search only through files that match a specific 'glob' pattern (eg: search for foo in all files named "bar*.c"). The command ack foo "bar*.c" only works in the current directory. Note: I know it's possible with find -exec: find . -name "bar*.c" -type f -exec ack foo {} + But I would like a small and simple ack command, because find doesn't skip version control directories.
compie (823 rep)
Apr 24, 2014, 10:37 AM • Last activity: Mar 28, 2024, 11:30 AM
16 votes
4 answers
13086 views
How to ignore multiple files with `ag` The Silver Searcher
There is an option `--ignore` which allows specifying files to ignore. At the moment I only managed to ignore multiple files by doing `--ignore file1 --ignore file2.......` Trying to use `--ignore "*assets*|*scripts*"` does nothing. So is there a catch I'm not aware of?
There is an option --ignore which allows specifying files to ignore. At the moment I only managed to ignore multiple files by doing --ignore file1 --ignore file2....... Trying to use --ignore "*assets*|*scripts*" does nothing. So is there a catch I'm not aware of?
T.Chmelevskij (263 rep)
May 3, 2017, 06:11 PM • Last activity: Dec 18, 2023, 04:21 PM
0 votes
1 answers
615 views
Behaviour of single and double quotes depending on shell
I've been scratching my head for quite some time with this.... Inspired by [this answer][1], I'm trying to run 'ack' and to find either a single quote or a double quote in source files. Doing this in **bash** perfectly works: `ack --cpp "['\"]"` But doing the same in **tcsh** gives me: `Unmatched "....
I've been scratching my head for quite some time with this.... Inspired by this answer , I'm trying to run 'ack' and to find either a single quote or a double quote in source files. Doing this in **bash** perfectly works: ack --cpp "['\"]" But doing the same in **tcsh** gives me: Unmatched ". One of the alternatives I have tried is to essentially swap the single and double quotes, leading to ack --cpp '[\'"]'. But I'm still getting the same Unmatched ". No matter what I try, I don't seem to be able to get the wanted behaviour in tcsh. Any suggestions ?
DaveC (1 rep)
Sep 2, 2021, 01:48 AM • Last activity: Jul 20, 2023, 02:33 PM
0 votes
1 answers
254 views
how to detect unbalanced special characters in string
I'm wondering what would be the best way (likely using **grep** or **ack**) to return lines containing *unbalanced special character sets* in a string? For example, if the string were: ``` bqM#+t1U"OyBGhk]ozVG[v"& ``` and the specified character were a double-quote ("), this line would not be return...
I'm wondering what would be the best way (likely using **grep** or **ack**) to return lines containing *unbalanced special character sets* in a string? For example, if the string were:
bqM#+t1U"OyBGhk]ozVG[v"&
and the specified character were a double-quote ("), this line would not be returned. However, what I'm looking for is more complicated, requiring a left and right balance, for instance a left square parenthesis ([) and a right square parenthesis (]). Then the line would be returned if the number of ([) does not equal the number of (]) such as:
i],U2y.2y[A~a`^[
irishwristwatch (1 rep)
Nov 16, 2022, 09:46 PM • Last activity: Nov 17, 2022, 03:51 PM
2 votes
2 answers
103 views
Why Doesn't This Shell Script Work?
I've got the following shell script #!/bin/bash # Search elixir code with ack # By default skip the dependencies and test directories ignore_dirs=("dependencies" "test" "config") # the for call below inserts newlines so we need to strip them out which is why the tr -d part is on the end # of the ass...
I've got the following shell script #!/bin/bash # Search elixir code with ack # By default skip the dependencies and test directories ignore_dirs=("dependencies" "test" "config") # the for call below inserts newlines so we need to strip them out which is why the tr -d part is on the end # of the assignment ign_dirs="$(for i in "${ignore_dirs[@]}"; do echo "--ignore-dir=$i "; done | tr -d '\n')" # By default skip the mix.exs file ignore_files=("is:mix.exs" "is:credo.exs") ign_files="$(for i in "${ignore_files[@]}"; do echo "--ignore-file=$i "; done | tr -d '\n')" pager=less file_types=elixir:ext:ex,exs,eex,heex #echo ack $1 --word-regexp --pager="$pager" --type-set="$file_types" "$ign_dirs" "$ign_files" --noenv # Array variation ack $1 --word-regexp --pager="$pager" --type-set="$file_types" "$ign_dirs" "$ign_files" --noenv # Hardcoded variation ack $1 --word-regexp --pager=less --type-set=elixir:ext:ex,exs,eex,heex --ignore-dir=dependencies --ignore-dir=test --ignore-dir=config --ignore-file=is:mix.exs --ignore-file=is:credo.exs --noenv I created the hardcoded variation with the commented out echo line. When I run the hardcoded variation ack works as expected. When I run the array variation it seems as if ack doesn't see the command line options--for example, mix.exs is included although it shouldn't be and it searches the test directory. Is my shell script wrong? I copy/paste most of the shell script--I mean I can
$ign_dirs
and I see the right value there and when I run the command (the array variation) it doesn't work correctly which seems to indicate that my shell script is fine. By the way, I'm running this on a mac on zsh. I did test this under bash and I see the same issue. Apologies in advance if this is some sort of ack FAQ somewhere. I did check but didn't find anything to point to a solution. EDIT: I can see that I wasn't as clear as I could have been. Ultimately I'm trying to automate the searching of Elixir code with ack. I want to keep my options/search within a bash script as much as possible so I won't have to worry about variations in .ackrc files and environment variables on different machines. What I'm expecting is that when ack searches the files it will exclude the directories I've listed in ignore_dirs as well as skipping the files I've specified in the ignore_files. When I run my shell script with the hardcoded variation, the directories get ignored. When I run my shell script with the array variation they do not get ignored. And yes, I know that ign_dirs and ign_files are strings not arrays. Is it possible to use the arrays directly on the command line in the shell script?
Onorio Catenacci (123 rep)
Jul 22, 2022, 08:56 PM • Last activity: Jul 23, 2022, 12:44 AM
1 votes
1 answers
151 views
ack regex logical OR
I want to ignore the file if the filename match any of these words : copy, cony, coby OR tool, trol, thol etc. This one works : ack -l -i --ignore-file=match:/co.y/ --ignore-file=match:/t.ol/ "mystring" _mynukelib But i want to use single --ignore parameter. I tried to use "|" to create "OR" logic l...
I want to ignore the file if the filename match any of these words : copy, cony, coby OR tool, trol, thol etc. This one works : ack -l -i --ignore-file=match:/co.y/ --ignore-file=match:/t.ol/ "mystring" _mynukelib But i want to use single --ignore parameter. I tried to use "|" to create "OR" logic like in normal regex but doesn't work : ack -l -i --ignore-file=match:/co.y|t.ol/ "mystring" _mynukelib What is the proper syntax to perform logical OR.
andio (113 rep)
Dec 25, 2021, 04:21 PM • Last activity: Dec 26, 2021, 12:40 PM
0 votes
1 answers
664 views
Understanding ACK numbers
I try to understand the reason of unordered ACK numbers. I have the following logs in wireshark: ``` 34936 → 80 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM=1 TSval=3595656117 TSecr=0 WS=128 2 0.003662105 192.168.1.1 192.168.1.2 TCP 66 80 → 34936 [SYN, ACK] Seq=0 Ack=1 Win=29200 Len=0 MSS=1460 SAC...
I try to understand the reason of unordered ACK numbers. I have the following logs in wireshark:
34936 → 80 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM=1 TSval=3595656117 TSecr=0 WS=128
    2	0.003662105	192.168.1.1	192.168.1.2	TCP	66	80 → 34936 [SYN, ACK] Seq=0 Ack=1 Win=29200 Len=0 MSS=1460 SACK_PERM=1 WS=32
    3	0.003691751	192.168.1.2	192.168.1.1	TCP	54	34936 → 80 [ACK] Seq=1 Ack=1 Win=64256 Len=0
    4	0.003803721	192.168.1.2	192.168.1.1	HTTP	767	POST /jrd/webapi?api=GetSystemStatus HTTP/1.1* (application/x-www-form-urlencoded)
    5	0.024447941	192.168.1.1	192.168.1.2	TCP	54	80 → 34936 [ACK] Seq=1 Ack=714 Win=32128 Len=0
    6	0.052296708	192.168.1.1	192.168.1.2	TCP	70	80 → 34936 [PSH, ACK] Seq=1 Ack=714 Win=32128 Len=16 [TCP segment of a reassembled PDU]
    7	0.052296845	192.168.1.1	192.168.1.2	HTTP/JSON	528	HTTP/1.1 200 OK , JavaScript Object Notation (application/json)
    8	0.052364039	192.168.1.2	192.168.1.1	TCP	54	34936 → 80 [ACK] Seq=714 Ack=17 Win=64256 Len=0
    9	0.052930703	192.168.1.2	192.168.1.1	TCP	54	34936 → 80 [FIN, ACK] Seq=714 Ack=492 Win=64128 Len=0
    10	0.061251843	192.168.1.2	192.168.1.1	TCP	74	34938 → 80 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM=1 TSval=3595656179 TSecr=0 WS=128
    11	0.064187519	192.168.1.1	192.168.1.2	TCP	54	80 → 34936 [ACK] Seq=492 Ack=715 Win=32128 Len=0
    12	0.064187779	192.168.1.1	192.168.1.2	TCP	66	80 → 34938 [SYN, ACK] Seq=0 Ack=1 Win=29200 Len=0 MSS=1460 SACK_PERM=1 WS=32
    13	0.064330872	192.168.1.2	192.168.1.1	TCP	54	34938 → 80 [ACK] Seq=1 Ack=1 Win=64256 Len=0
    14	0.065632767	192.168.1.2	192.168.1.1	HTTP	772	POST /jrd/webapi?api=GetSMSStorageState HTTP/1.1* (application/x-www-form-urlencoded)
    15	0.066381036	192.168.1.2	192.168.1.1	TCP	74	34940 → 80 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM=1 TSval=3595656184 TSecr=0 WS=128
    16	0.074954073	192.168.1.1	192.168.1.2	TCP	66	80 → 34940 [SYN, ACK] Seq=0 Ack=1 Win=29200 Len=0 MSS=1460 SACK_PERM=1 WS=32
    17	0.075028197	192.168.1.2	192.168.1.1	TCP	54	34940 → 80 [ACK] Seq=1 Ack=1 Win=64256 Len=0
    18	0.075349695	192.168.1.2	192.168.1.1	HTTP	772	POST /jrd/webapi?api=GetConnectionState HTTP/1.1* (application/x-www-form-urlencoded)
    19	0.080664337	192.168.1.1	192.168.1.2	TCP	70	80 → 34938 [PSH, ACK] Seq=1 Ack=719 Win=32128 Len=16 [TCP segment of a reassembled PDU]
    20	0.080664489	192.168.1.1	192.168.1.2	HTTP/JSON	304	HTTP/1.1 200 OK , JavaScript Object Notation (application/json)
    21	0.080744236	192.168.1.2	192.168.1.1	TCP	54	34938 → 80 [ACK] Seq=719 Ack=17 Win=64256 Len=0
    22	0.081363475	192.168.1.2	192.168.1.1	TCP	54	34938 → 80 [FIN, ACK] Seq=719 Ack=268 Win=64128 Len=0
    23	0.084534363	192.168.1.1	192.168.1.2	TCP	54	80 → 34938 [ACK] Seq=1 Ack=719 Win=32128 Len=0
    24	0.084606985	192.168.1.2	192.168.1.1	TCP	54	[TCP Dup ACK 22#1] 34938 → 80 [ACK] Seq=720 Ack=268 Win=64128 Len=0
    25	0.084649572	192.168.1.1	192.168.1.2	TCP	54	80 → 34940 [ACK] Seq=1 Ack=719 Win=32128 Len=0
    26	0.084649729	192.168.1.1	192.168.1.2	TCP	54	80 → 34938 [ACK] Seq=268 Ack=720 Win=321
    27	0.086781498	192.168.1.1	192.168.1.2	TCP	70	80 → 34940 [PSH, ACK] Seq=1 Ack=719 Win=32128 Len=16 [TCP segment of a reassembled PDU]
1. In string number 8 Seq=714 Ack=17. But in string number 9 Seq=714 Ack=492. I thought that Ack here 714+17=731. How Ack is calculate here and why it is 492? The same question about calculation Ack number in string 22 where Ack=268, not 736 as i expected. 2. In string number 9 there is FIN ASK flag following by SYN flag. But in string number 13 i see ASK flag following by SYN flag. I don't see FIN flag. Thank you a lot for any answers. I need to understand low-lewel TCP basis.
Tina (104 rep)
Oct 13, 2021, 02:20 AM • Last activity: Oct 13, 2021, 03:40 AM
64 votes
4 answers
53472 views
How to do max-depth search in ack and grep?
Is there any way to tell `ack` to only search for text on the current folder? (or specify a `max-depth` level?) And with `grep`?
Is there any way to tell ack to only search for text on the current folder? (or specify a max-depth level?) And with grep?
Amelio Vazquez-Reina (42851 rep)
Jan 30, 2014, 07:23 PM • Last activity: Sep 8, 2021, 08:25 AM
2 votes
5 answers
1230 views
Why can't I pipe to ack?
So I've been trying to use `grep` to extract some stuff from a Mercurial log and trying to avoid using `awk` just to see if I can get by without it here, and failing because neither `grep` nor `egrep` support full modern regex. So this happens with grep: $ hg log | grep changeset changeset: 3651:d23...
So I've been trying to use grep to extract some stuff from a Mercurial log and trying to avoid using awk just to see if I can get by without it here, and failing because neither grep nor egrep support full modern regex. So this happens with grep: $ hg log | grep changeset changeset: 3651:d23495ab1168 changeset: 2974:6aa71cb2c575 changeset: 2756:9dd7fb635678 changeset: 2532:d3ced9af4d6c changeset: 2459:9d5f5553b851 changeset: 1835:4558836beed1 changeset: 1628:517d0239e830 changeset: 1486:114bce51254d changeset: 1378:2b968e7fbd19 changeset: 1374:4e7772e48d00 This is what I want in terms of output results. But to get better regex support, I tried doing this with ack, aaaand....nothing. What am I missing? Checked a bunch of examples and can see no difference in what I'm doing here. $ hg log | ack changeset $ There is no output. Maybe I am misunderstanding this tool? egrep did not have enough support either. I just want to use \s :(
temporary_user_name (595 rep)
Apr 16, 2015, 10:25 PM • Last activity: Nov 21, 2020, 08:34 AM
2 votes
1 answers
3082 views
fast retransmit does not work
Fast retransmit says that if 3 dupacks have been received by sender, then the sender should retransmit the lost packet. But my tcpdump output shows that it didn't work like this. It didn't retransmit the packet even more than 10 dupacks have been received. Why didn't it triggerfast retransmit? Does...
Fast retransmit says that if 3 dupacks have been received by sender, then the sender should retransmit the lost packet. But my tcpdump output shows that it didn't work like this. It didn't retransmit the packet even more than 10 dupacks have been received. Why didn't it triggerfast retransmit? Does anyone has idea about this? Thanks `cat /proc/version: Linux version 4.2.0-42-generic (buildd@lgw01-55) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) ) #49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 2016 ` `sysctl: net.ipv4.tcp_congestion_control = cubic` enter image description here
chengtcli (21 rep)
Aug 28, 2016, 05:08 AM • Last activity: Jun 28, 2020, 07:00 PM
4 votes
2 answers
343 views
ack : get the 10th (or bigger nth) matching/capturing group
I think I might have just searched wrong, but I didn't find any answer. If there's a duplicate, please just let me know, and I can take this down. Problem Background I'm using `ack` ([link](https://beyondgrep.com/)), which has Perl 5 under the hood, to get n-grams - especially higher-order n-grams....
I think I might have just searched wrong, but I didn't find any answer. If there's a duplicate, please just let me know, and I can take this down.

Problem Background

I'm using ack ([link](https://beyondgrep.com/)) , which has Perl 5 under the hood, to get n-grams - especially higher-order n-grams. I can get up to 9-grams using the syntax I know (basically up to $9), but I haven't been able to get the 10-grams. Using $10 just gives me $1 with a 0 after it. Things like $(10) and ${10} did not solve the problem. I'm _NOT_ interested in a solution using a language-modelling toolkit, I want to use ack. One dataset I'm using is the complete works of Mark Twain ( wget http://www.gutenberg.org/cache/epub/3200/pg3200.txt && mv pg3200.txt TWAIN_Mark_complete_orig.txt ). I've parsed things clean (see the _Parsing Note_ at the end of the post) and saved the parsed result as TWAIN_Mark_complete_parsed.txt. I've been fine getting from 2-grams, with the code and partial results for that being
time cat TWAIN_Mark_complete_parsed.txt | \
    ack '(\S+) +(?=(\S+) +)' \
    --output '$1 $2' | \
    sort | uniq -c | \
    sort -rn > Twain_2grams.txt
## time info not shown
$ head -n 2 Twain_2grams.txt
  18176 of the
  13288 in the
all the way up to 9-grams, with
time cat TWAIN_Mark_complete_parsed.txt | \
    ack '(\S+) (?=(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+))' \
    --output '$1 $2 $3 $4 $5 $6 $7 $8 $9' | \
    sort | uniq -c | sort -rn > Twain_9grams.txt
## time info not shown
$ head -n 2 Twain_9grams.txt
     17 to mrs jane clemens and mrs moffett in st
     17 mrs jane clemens and mrs moffett in st louis
(N.B. I meta-program the ack commands, rather than just typing every single one.)

The Problem / What I've Tried

My first try with 10-grams, as well as the result, was
time cat TWAIN_Mark_complete_parsed.txt | \
    ack '(\S+) (?=(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(\S+))' \
    --output '$1 $2 $3 $4 $5 $6 $7 $8 $9 $10' | \
    sort | uniq -c | sort -rn > Twain_10grams.txt

$ head -n 2 Twain_10grams.txt
     17 to mrs jane clemens and mrs moffett in st to0
     17 mrs jane clemens and mrs moffett in st louis mrs0
To better see what's happening, [![diff -u Expected/Desired Output Note that there _is_ a statistical (_very_ non-zero and finite) possibility of the real output being different from the one shown here. The top two results for 9-grams were not distinct sequences of words. Other possible parts of a more-common 10-gram might be found by looking at the top 10 most frequent 9-grams - using head instead of head -n 2. Even so, I'm fairly certain that not even this would guarantee that we have the two most frequent 10-grams. I hope, however, that I'm making it clear enough what I'm wanting to accomplish. 17 to mrs jane clemens and mrs moffett in st louis
3 mrs jane clemens and mrs moffett in st louis honolulu **Edit** I've already found another set that changes expected output to (possibly not the actual output, but one that changes it from the simple model I used before.)
17 to mrs jane clemens and mrs moffett in st louis
      7 happiness in his home had been wounded and bruised almost
That would be for the head -n 2 that I've been using to show what kind of results I get. I don't want to get it by the same process I'm going to use here.
$ grep -o "to mrs jane clemens and mrs moffett in st [^ ]\+" \
   TWAIN_Mark_complete_parsed.txt | sort | uniq -c | sort -rn
     17 to mrs jane clemens and mrs moffett in st louis

$ grep -o "mrs jane clemens and mrs moffett in st louis [^ ]\+" \
   TWAIN_Mark_complete_parsed.txt | sort | uniq -c | sort -rn
      3 mrs jane clemens and mrs moffett in st louis honolulu
      2 mrs jane clemens and mrs moffett in st louis san
      2 mrs jane clemens and mrs moffett in st louis no
      2 mrs jane clemens and mrs moffett in st louis 224
      1 mrs jane clemens and mrs moffett in st louis wash
      1 mrs jane clemens and mrs moffett in st louis wailuku
      1 mrs jane clemens and mrs moffett in st louis virginia
      1 mrs jane clemens and mrs moffett in st louis the
      1 mrs jane clemens and mrs moffett in st louis sept
      1 mrs jane clemens and mrs moffett in st louis on
      1 mrs jane clemens and mrs moffett in st louis hartford
      1 mrs jane clemens and mrs moffett in st louis carson
**Edit** The code used to find the newer second-place frequency was
$ grep -o "[^ ]\+ happiness in his home had been wounded and bruised" TWAIN_Mark_complete_parsed.txt | sort | uniq -c | sort -rn
      6 shelley's happiness in his home had been wounded and bruised
      1 his happiness in his home had been wounded and bruised
$ grep -o "shelley's happiness in his home had been wounded and [^ ]\+" TWAIN_Mark_complete_parsed.txt | sort | uniq -c | sort -rn
      6 shelley's happiness in his home had been wounded and bruised
$ grep -o "happiness in his home had been wounded and bruised [^ ]\+" TWAIN_Mark_complete_parsed.txt | sort | uniq -c | sort -rn
      7 happiness in his home had been wounded and bruised almost
$ grep -o "in his home had been wounded and bruised almost [^ ]\+" TWAIN_Mark_complete_parsed.txt | sort | uniq -c | sort -rn
      7 in his home had been wounded and bruised almost to
$ grep -o "his home had been wounded and bruised almost to [^ ]\+" TWAIN_Mark_complete_parsed.txt | sort | uniq -c | sort -rn
      7 his home had been wounded and bruised almost to death
$ grep -o "home had been wounded and bruised almost to death [^ ]\+" TWAIN_Mark_complete_parsed.txt | sort | uniq -c | sort -rn
      1 home had been wounded and bruised almost to death thirdly
      1 home had been wounded and bruised almost to death secondly
      1 home had been wounded and bruised almost to death it
      1 home had been wounded and bruised almost to death fourthly
      1 home had been wounded and bruised almost to death first
      1 home had been wounded and bruised almost to death fifthly
      1 home had been wounded and bruised almost to death and

Edit from Comment

@Inian made a great [comment](https://unix.stackexchange.com/questions/593467/ack-get-the-10th-or-bigger-nth-matching-capturing-group#comment1107135_593467) : > This is documented in the release notes - [github.com/beyondgrep/ack3/blob/dev/RELEASE-NOTES.md](https://github.com/beyondgrep/ack3/blob/dev/RELEASE-NOTES.md) - You're now restricted to the following variables: $1 thru $9, $, $., $&, $` , $' and $+_ For [future people](https://xkcd.com/979/) , I'm putting a [version, archived today](https://web.archive.org/web/20200617164916/https://github.com/beyondgrep/ack3/blob/dev/RELEASE-NOTES.md#ack-3s---output-allows-fewer-special-variables) , of the RELEASE-NOTES The man page for ack does have the lines > $1 through $9
The subpattern from the corresponding set of capturing parentheses.
If your pattern is "(.+) and (.+)", and the string is "this and that',
then $1 is "this" and $2 is "that". but I was hoping there was a way to get higher numbers. With the info from the RELEASE-NOTES, that hope seems mostly gone. *However*, I still wonder if anyone has a work-around or hack, whether using ack or any of the more 'standard' *NIX-type terminal tools. My preference, in order, would be perl, grep, awk, sed. If there's something similar to ack (i.e. just command-line parsing, _NOT_ an NLP-toolkit-based solution), I'm interested in that, too. I think it might be better to pose this as a new question. If you answer here, great. If I end up posting a new question, I will put the link here: [for now, this is just a link to this same question](https://unix.stackexchange.com/q/593467/291375) .

Parsing Note

To get my corpus ready for n-gram analysis, here was my parsing.
tr [:upper:] [:lower:]  TWAIN_Mark_complete_parsed.txt && \
# collapse all multiple spaces to one space (includes tabs), save to output
:
Yes, that could all be on one line (and without the trailing && :), but this makes for easier reading as well as explanation of why I'm doing what I'm doing.

System Details

$ uname -a
CYGWIN_NT-10.0 MY_MACHINE 3.0.7(0.338/5/3) 2019-04-30 18:08 x86_64 Cygwin
$ bash --version | head -n 1
GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)
$ ack --version | head -n 2
ack v3.3.1 (standard build)
Running under Perl v5.26.3 at /usr/bin/perl.exe
$ systeminfo | sed -n 's/^OS\ *//p'
Name:                   Microsoft Windows 10 Enterprise
Version:                10.0.17134 N/A Build 17134
Manufacturer:           Microsoft Corporation
Configuration:          Member Workstation
Build Type:             Multiprocessor Free
bballdave025 (418 rep)
Jun 17, 2020, 03:30 PM • Last activity: Jun 18, 2020, 07:29 AM
0 votes
1 answers
663 views
How to grep contents in HEX specifying the pattern in decimals?
I have a file with the following contents (as a text file in UTF-8) ``` e04ba1af81d887979ddcee1dc23f2531 43f85926fdb6a668386ee354f8b836a1 b53614f5139c052ec08ea1ecd2532daf e9b3914d7b1e1bf8e6feab621330245b bbcad02116316176385fbfb294ee77b4 ``` I need to ensure that this file contains a number `46390` (...
I have a file with the following contents (as a text file in UTF-8)
e04ba1af81d887979ddcee1dc23f2531
43f85926fdb6a668386ee354f8b836a1
b53614f5139c052ec08ea1ecd2532daf
e9b3914d7b1e1bf8e6feab621330245b
bbcad02116316176385fbfb294ee77b4
I need to ensure that this file contains a number 46390 (decimal). It equals b536 in HEX that is the beginning of the 3rd line. How do I use grep or awk to make it convert both file and pattern to binary representation and then do a search? In other words, make searching base independent considering that bases are known. Sample output: 1)
$ cat file.txt | grep 46390
**1011010100110110**1010011110101000100111001110000000101001011101100000010001110101000011110110011010010010100110010110110101111 (it's **b536**14f5139c052ec08ea1ecd2532daf in hex) 2) A file contains a single string 3CA547A (binary 0011110010100101010001111010). I am given a decimal representation of some sequence. The file may contain this sequence and it may be not aligned by 8 bits. Let's assume this sequence is equal to decimal 15 (binary 1111) The command:
$ cat file.text | grep 15
The result would contain 2 occurrences: 00**1111**001010010101000**1111**010
Enbugger (109 rep)
Aug 28, 2019, 02:11 AM • Last activity: Aug 28, 2019, 05:49 PM
2 votes
1 answers
167 views
Can ack read patterns from a file?
`grep` can look for a list of patterns written in a file with `grep -f patterns_file search_files` Can `ack` read a list of patterns from a file?
grep can look for a list of patterns written in a file with grep -f patterns_file search_files Can ack read a list of patterns from a file?
lolesque (341 rep)
May 28, 2019, 01:35 PM • Last activity: May 28, 2019, 01:37 PM
1 votes
2 answers
336 views
How to highlight terms in an output that has a live update?
I'm doing a loop over ffmpeg to convert a bunch of videos, and I would like to highlight some terms in ffmpeg's output. But the solution I tried always made the live progress of the conversion disappear. What I have tried is mainly to redirect stderr to stdout, and grep or ack like this (ffmpeg's co...
I'm doing a loop over ffmpeg to convert a bunch of videos, and I would like to highlight some terms in ffmpeg's output. But the solution I tried always made the live progress of the conversion disappear. What I have tried is mainly to redirect stderr to stdout, and grep or ack like this (ffmpeg's command is simplified for readability) : ffmpeg -i input.mp4 ouput.mkv 2>&1 | ack --passthru --color "pcm_s16le|aac" or ffmpeg -i input.mp4 ouput.mkv 2>&1 | grep -E "pcm_s16le|aac|$" (note the |$ hack that allow to match everything without coloring it, acting like a passthrough) And what I mean by live progress info is the line that look like this : frame=190 fps=3.7 q=-0.0 size=308kB time=06:08.66 bitrate=677kbits/s speed=0.17x So, is there a way to highlight some words that output, _and_ keep the live progress ?
Cqoicebordel (11 rep)
Feb 12, 2019, 11:44 PM • Last activity: Feb 13, 2019, 09:33 PM
2 votes
3 answers
1855 views
Web front-end to find/grep/ack
In my lab, we are trying to build a web that allows the user to enter **queries** for `find`, `ack`, `grep` on a specific directory. The web would return an HTML with a table of a list of clickable files (click on them would download the file). For example, in this interface the user would type a wo...
In my lab, we are trying to build a web that allows the user to enter **queries** for find, ack, grep on a specific directory. The web would return an HTML with a table of a list of clickable files (click on them would download the file). For example, in this interface the user would type a word in a form in the browser, and the system would call find . -name "*word*" and send back an HTML with the result. Has anything like this been done before? We would like to avoid reinventing the wheel. What toolkits, utilities or packages would be helpful to build this functionality?
Amelio Vazquez-Reina (42851 rep)
Oct 15, 2012, 05:22 PM • Last activity: Jan 30, 2018, 06:35 PM
1 votes
0 answers
53 views
Can ag search sub-directories with the same name, within a bunch of directories?
Given a directory structure such as: dev/project1/assets/** dev/project2/assets/** dev/project3/assets/** Is it possible to search, from within the dev directory all assets directories only. Given that the project directories will include other sub-directories. I don't want to have to explicitly nam...
Given a directory structure such as: dev/project1/assets/** dev/project2/assets/** dev/project3/assets/** Is it possible to search, from within the dev directory all assets directories only. Given that the project directories will include other sub-directories. I don't want to have to explicitly name each project directory. But something like search on /*/*/assets. So x directories deep, with a given name.
Kris (255 rep)
Oct 23, 2017, 07:52 AM • Last activity: Oct 23, 2017, 11:35 AM
0 votes
1 answers
430 views
Ack/Ag does not return search result without *
I am trying to search text in a directory and it turned out that the following syntaxes do not return any result ack -i "0xabcdef" ./ ack -i "0xabcdef" ack -i "0xabcdef" . while the following command works ack -i "0xabcdef" * Can someone explain why that is the case? What is the significance of `*`?...
I am trying to search text in a directory and it turned out that the following syntaxes do not return any result ack -i "0xabcdef" ./ ack -i "0xabcdef" ack -i "0xabcdef" . while the following command works ack -i "0xabcdef" * Can someone explain why that is the case? What is the significance of *? I also noticed that the directory has symbolic links.
user2065276 (105 rep)
Aug 1, 2017, 03:12 PM • Last activity: Aug 2, 2017, 12:31 AM
3 votes
0 answers
189 views
Using ack to effectively search and RStudio project directory
I'm interested in running `ack` search on a [RStudio][1] project directory that mostly contains `*.R` script files but also some project files and often `*.git` files. # Directory The project folder structure created from a default [Shiny][2] application: $ tree . ├── SomeNosense.Rproj ├── server.R...
I'm interested in running ack search on a RStudio project directory that mostly contains *.R script files but also some project files and often *.git files. # Directory The project folder structure created from a default Shiny application: $ tree . ├── SomeNosense.Rproj ├── server.R └── ui.R # Search Given this I'm interested in running a simple search for a word ***old*** across the ***.R** files only. *The sample shiny app created as a defult projects has some strings where the word **old** is mentioned*. ack -i -rr 'Old' I'm getting results that do not match what should correspond to ack --help-types, which shows: --[no]rr .R ## Results whereas my results for this command are very messy: .Rproj.user/38B87E11/sdb/s-FEC4716C/28624A5C 7: "folds" : "", .Rproj.user/38B87E11/sdb/s-FEC4716C/8A580C19 3: "contents" : "\n# This is the user-interface definition of a Shiny web application.\n# You can find out more about building applications with Shiny here:\n#\n# http://shiny.rstudio.com\n#\n\nlibrary(shiny)\n\nshinyUI(fluidPage(\n\n # Application title\n titlePanel(\"Old Faithful Geyser Data\"),\n\n # Sidebar with a slider input for number of bins\n sidebarLayout(\n sidebarPanel(\n sliderInput(\"bins\",\n \"Number of bins:\",\n min = 1,\n max = 50,\n value = 30)\n ),\n\n # Show a plot of the generated distribution\n mainPanel(\n plotOutput(\"distPlot\")\n )\n )\n))\n", 7: "folds" : "", ui.R 13: titlePanel("Old Faithful Geyser Data"), # Desired results Desired results can be achieved with grep: me-547/47:SomeNosense$ grep -r -i 'old' ~/Documents/SomeNosense/*.R /Users/me/Documents/SomeNosense/ui.R: titlePanel("Old Faithful Geyser Data"), # Question What is wrong with my [tag:ack] command that I'm not getting the same results? --- The ag also seems to be returning more accurate results: me-552/52:SomeNosense$ ag -rr -i 'old' ui.R 13: titlePanel("Old Faithful Geyser Data"), me-553/53:SomeNosense$ ack -rr -i 'old' .Rproj.user/38B87E11/sdb/per/t/28624A5C 7: "folds" : "", .Rproj.user/38B87E11/sdb/per/t/8A580C19 3: "contents" : "\n# This is the user-interface definition of a Shiny web application.\n# You can find out more about building applications with Shiny here:\n#\n# http://shiny.rstudio.com\n#\n\nlibrary(shiny)\n\nshinyUI(fluidPage(\n\n # Application title\n titlePanel(\"Old Faithful Geyser Data\"),\n\n # Sidebar with a slider input for number of bins\n sidebarLayout(\n sidebarPanel(\n sliderInput(\"bins\",\n \"Number of bins:\",\n min = 1,\n max = 50,\n value = 30)\n ),\n\n # Show a plot of the generated distribution\n mainPanel(\n plotOutput(\"distPlot\")\n )\n )\n))\n", 7: "folds" : "", ui.R 13: titlePanel("Old Faithful Geyser Data"), RStudio: 1.0.143
Konrad (363 rep)
Jul 15, 2016, 11:41 AM • Last activity: Jun 26, 2017, 08:00 AM
3 votes
1 answers
835 views
Ignore files without extension in ack
I would like to define a file type that would enable me to ignore all files without extension in `ack`. In my `.ackrc` file I have added: --type-set=csv:ext:csv,tsv To handle CSV files that I often exclude from searches via `--nocsv` switch when running `ack` query. However, some of the files I woul...
I would like to define a file type that would enable me to ignore all files without extension in ack. In my .ackrc file I have added: --type-set=csv:ext:csv,tsv To handle CSV files that I often exclude from searches via --nocsv switch when running ack query. However, some of the files I would like to exclude have no CSV extension. Ideally, I would like to be able to arrive at a syntax: ack --nocsv --nosansext searchStuff ~/SomeProjects I would like for this command to: - Exclude CSV files - Exclude files without extension - Include all other syntax files that I have in SomeProjects folder. Is it possible to define a file type in ack to capture files without extension?
Konrad (363 rep)
May 11, 2017, 10:51 AM • Last activity: May 11, 2017, 11:21 AM
2 votes
1 answers
19842 views
Mac Terminal command - Find string and print with surrounding line
I have been testing using ack, sed, grep trying to search through files in a directory to find a particular string. I am looking through my database files to check to see if passwords are listed in clear text. So far, I have been able to use this command: grep -Ri "search_string" /path_to_Folder How...
I have been testing using ack, sed, grep trying to search through files in a directory to find a particular string. I am looking through my database files to check to see if passwords are listed in clear text. So far, I have been able to use this command: grep -Ri "search_string" /path_to_Folder However, this only outputs the files that contain the string. I want to go one step further and print out the line around the string so I don't have to go in and search each file. I hope that make sense. Thank you so much.
user3324136 (123 rep)
Feb 26, 2017, 02:39 AM • Last activity: Feb 27, 2017, 02:19 AM
Showing page 1 of 20 total questions