date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,321,145,927,000
Are there any utilities to filter a sample from a stream on the command-line, e.g. print every 100th line of a file or print a line of a file out with probability 0.01 or via algorithms like reservoir sampling? Update: So far I found: print every 100th line of a file: sed -n '0~100p'
The simple solutions with (GNU) awk: Every one in 100 (lines with number divisible by 100): do_something | awk 'NR % 100 == 0' or pseudorandomly: do_something | awk 'rand() < 0.01' The numbers will likely not be exactly uniform and it may be necessary to add BEGIN{ srand() } to initialize a new seed for each run.
Take a sample from a file or stream?
1,321,145,927,000
I want to parse some output so I exclude all lines that contain either foo or bar, as well as all lines immediately preceding those lines. For example: echo " 1 some line 2 line to exclude because the next line has one of the terms 3 line with foo 4 line to exclude because the next line has one of the terms too 5 line...
Here's the more verbose version of essentially the same thing @1_CR posted above and @ ash showed at pastebin, hopefully using more readable syntax: awk '{ lastLine = currentLine; currentLine = $0; } /foo|bar/ \ { getline currentLine next } NR > 1 \ { p...
grep filter all lines plus one before each hit
1,321,145,927,000
I have sample: "name": "The title of website", "sync_transaction_version": "1", "type": "url", "url": "https://url_of_website" I want to get the following output: "The title of website" url_of_website I need to remove the protocol prefix from the URL, so that only url_o...
This works on the JSON document given in the question: $ jq -r '.roots.bookmark_bar.children[]|.children[]|["\"\(.name)\"",.url]|@tsv' file.json "The title is here" https://the_url_is_here "The title here" https://url_here This accesses the .children[] array of each .roots.bookmark_bar.children[] array ent...
How to combine strings from JSON values, keeping only part of the string?
1,321,145,927,000
I read the man page but I could not find how to use -f when using tmux list-panes. It seems to be a filter, I assume this works like grep in some way? Does anyone know how -f works?
The -f option existed already on some other commands, like choose-tree where a hint as to how it works is given. It takes a format string, and, for each pane, if that evaluates to true (i.e. not 0 nor empty) then that pane is listed. For example, if you have 2 panes, one of which is in tree-mode: $ tmux list-panes -F ...
How does tmux list-panes -f (filter) work?
1,321,145,927,000
I want to back up my /home directory with rsync. I have read rsync's man page and decided to use filter rules for this task. What I would like to achieve: Exclude all files and directories in the Repos directory but keep all pull_all.sh files and output directories --- regardless where they are located within the Rep...
Slightly restating what I've interpreted as your requirements, Include all pull_all.sh files regardless of where we find them Include all output directories and their contents regardless of where we find them Exclude the Repos directory, other than what we have already stated Include everything else This can be spec...
rsync: Use filters to exclude top-level directory but include some of its subdirectories
1,321,145,927,000
How to specify multiple filter conditions connected with AND in less? I would like to filter a log having lines do NOT contain "nat" but contains an IP address 192.168.1.1, like: &/!nat && 192.168.1.1 However it does not work, the result is empty... Please advise.
I am convinced less do not allow to display only lines with 192.168.1.1 but without nat. You can use | (or) ||, & and && do not exist You can only invert match for the whole expression (with ! at the beginning), but ! is not special after An alternative is to use sed before less. sed -n -e '/nat/ d' -e '/192\.168\.1...
less: multiple filter conditions with AND
1,321,145,927,000
I'm trying to filter unwanted messages from a cron job (systemd) from rsyslog output. However rsyslog always complains about the second argument of re_match(). The filter rule I have is: if $programname == "systemd" and re_match($msg, '^Started [Ss]ession \d+ of user ntpmon\.$') then stop I started putting the regex ...
You need to double the backslash, otherwise rsyslog tries to interpret \d as an escape sequence within a string, and this is not parseable. So it should be \\d. But \d is not a Posix ERE. You presumably meant [0-9], for example, for a digit. So try '^Started [Ss]ession [0-9]+ of user ntpmon\\.$'
What is the correct syntax for rsyslog's re_match()?
1,321,145,927,000
I want to take a list of numbers representing line numbers of a source file I want to filter and filter those lines from the source file. How I can build a unix pipeline to extract these lines from the source file? The pipeline might look like: cat sourcefile.tsv | some-filter linenumbers.txt > extractedrecords.tsv ...
Assuming linenumbers.txt has one number per line awk 'NR == FNR{a[$0]; next};FNR in a' linenumbers.txt sourcefile.csv > extractedrecords.tsv Might do the job. Or, with bash join -t':' -o2.1,2.2 <(sort linenumbers.txt) <(awk '{print NR":"$0}' \ sourcefile.csv | sort -k1,1 -t':') | sort -k1,1n -t':' | cut -f2- -d':'...
How do I efficiently select specific line numbers from a list of records?
1,321,145,927,000
I'm analyzing some packetfilter logs and wanted to make a nice table of some output, which normally works fine when I use column -t. I can't use a tab as my output field separator (OFS) in this case because it jacks up the multi-word string fields with the table view. My original data consists of rows like this: 2018:...
I can reproduce your issue if I insert a row in the CSV file who's first comma-separated value is a very long string. name action srcip srcport dstip dstport protocol tcpflags SYN flo...
Why is column adding a newline in the middle of my row where one is not present in the original data?
1,435,844,238,000
I'm trying to create an exim filter to block spam messages containing " 85% OFF" in the subject line. That's a blank space, then any two digits, then the percent sign, a blank space and the word OFF in all caps. This is what I wrote: # Exim filter if $header_subject: contains " \\d{2}% OFF" then fail text "no ...
I temporarily replaced my .forward file with yours and confirmed that it doesn't work. There are two problems. contains performs a substring match, and does not understand regular expressions. For regexes you want matches rather than contains. The \d PCRE-style character class appears to be broken as does the {N} syn...
regex usage in exim filtering
1,435,844,238,000
I'm trying to set a couple of DNS servers to resolve only specified domains. My first attempt was to run DNSmasq and create a manual list of domains/IPs, like so: no-resolv address=/whatsapp.com/192.155.212.202 But big services like google, twitter, whatsapp, facebook, etc.. use several IP ranges and distribute them ...
You're looking for the server= directive instead of the address= directive. Unfortunately, you'll have to specify your actual DNS servers, it won't get them from resolv.conf (since you are using no-resolv to prevent that). server=/whatsapp.com/8.8.8.8 server=/whatsapp.com/8.8.4.4 server=/example.com/8.8.8.8 server=/ex...
DNS whitelist domains
1,435,844,238,000
OpenDNS offers a quite simple way for internet filtering by categories. Of course who could get the correct IP address can easily bypass the filter but it would be enough for my expectations. The bigger problem is that changing DNS provider at client side is not a big deal. So my question is whether it is possible to ...
With iptables firewall this works (Openwrt also uses iptables): iptables -t nat -A PREROUTING -s 192.168.1.0/24 -p udp --dport 53 -j DNAT --to 192.168.1.1 iptables -t nat -A PREROUTING -s 192.168.1.0/24 -p tcp --dport 53 -j DNAT --to 192.168.1.1 On your router use Opendns servers. 192.168.1.1 is the Openwrt router ip...
Force to use specific DNS provider at network
1,435,844,238,000
I have a 400MB+ Tomcat log file (catalina.out). How can I pull out entries for a given time period?
Not sure if this would work well for your 400MB file, but here are some CLI one liners that would do the trick. If you're looking for entries for a specific date, grep -c can probably do what you need. Otherwise, you could probably use sed: sed -n '/date1/,/date2/p' filename For example with an input file "test": Day...
How can I get entries for a given time period from a 400MB+ log file?
1,435,844,238,000
How to get a list of the latest files with the extension .jmx recursively and use the file names in another process? I have a list of JMX files organized into different folders and want to pick the latest file in each subfolder and use the JMX files in another process. (run the JMeter tests) Ideally, the latest file s...
With zsh, you could do: typeset -A latest for jmx (**/*.jmx(nN)) latest[$jmx:h]=$jmx Which builds the $latest associative array, where latest[some/dir]=some/dir/file-99.jwx with the value being the file whose name sorts last numerically (thanks to the n glob qualifier which enables numericglobsort for that glob). Th...
How to get a list of latest files recursively with a specific extension and copy them into a folder
1,435,844,238,000
I use the tail, head and grep commands to search log files. Most of the time the combination of these 3 commands, in addition to using pipe, gets the job done. However, I have this one log that many devices report to literally every few seconds. So this log is very large. But the pattern of the reporting is the same: ...
awk '$3 >= "11:58" && $3 <= "23:58" && /Unit ID: 1111/{print l"\n"$0};{l=$0}'
Search and Filter Text on large log files
1,435,844,238,000
Can anyone point me at a 'pick' filter script that works somewhat as described below? I've spent about an hour hunting for a simple bash script/filter that will allow me to pipe in a list of values and will spit out a subset of them depending on choices I make at the console. I know there are examples written in C but...
Self-demonstrating example using sed line specifiers (where N,M means lines N through M): $ ./pick.sh < ./pick.sh Lines: 1 #!/usr/bin/env bash 2 3 set -o errexit -o nounset -o noclobber 4 5 trap 'rm --force --recursive "$working_directory"' EXIT 6 working_directory="$(mktemp --dir...
Picking selected items from stdin via choices typed into console
1,435,844,238,000
I have a fairly simple little script. Basically, it performs ping over a given domain. It is like this: ping -c2 $1 | head -n4 And it prints out for example: PING google.com (172.217.17.206): 56 data bytes 64 bytes from 172.217.17.206: icmp_seq=0 ttl=55 time=2.474 ms 64 bytes from 172.217.17.206: icmp_seq=1 ttl=55 t...
If you don't want it to be stuck for "several seconds" when a server fails to respond, add a timeout using the -W option. For example: ping -c2 -W2 "$1" -W2 sets a two-second time. Change the limit to fit your needs. Aside When referencing shell variables, like $1, always put them in double-quotes, like "$1", unles...
Filtering the output from the ping command
1,435,844,238,000
I've got a folder with several thousand files with names like ousjgforuigor-TIMESTAMP.txt The timestamp is a standard Unix timestamp (e.g. 1543932635). Is there an easy way to list only files with a filename-timestamp > a provided one? The number of characters before the timestamp is variable, but the name always ends...
Using zsh's expression-as-a-glob-qualifier, t=1543951252 zsh -c 'datefilter() { ts=${REPLY##*-}; ts=${ts%*.txt}; ((ts >= $t)) }; print -l *-<->.txt(+datefilter)' The overall command (towards the end) is print -l, which prints each argument on a separate line. Well, the overall command is a presumed bash shell call t...
Filter files by string timestamp in filename
1,435,844,238,000
For example, I want to get only the 3rd element in each row when I call: xinput --list --short|grep "slave pointer" I get the output: ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ SynPS/2 Synaptics TouchPad id=11 [slave pointer (2)] ⎜ ↳ MCE IR Keyboard/Mouse...
Gawk is pretty simple for this kind of thing but OK, you can also use cut: xinput --list --short|grep "slave pointer" | cut -f 1 That will also include the leading space and ↳ characters. If you need to get rid of those, try this: xinput --list --short|grep "slave pointer" | cut -f 1 | cut -d" " -f 5-
Filtering the Xth element in a row?
1,435,844,238,000
I want to construct a huge blob of data (a backup of a sort) and send it over the network (ssh or rsync) to another host. There is enough space on the remote for the data, but not on the local host, so I cannot store it as a local file. I'd like to compute a checksum of the data as it is entering the pipe (and later c...
You can use tee and process substitution >(…), e.g. cat blob | tee >(md5sum >&2) | ssh user@remote 'tee >(md5sum >&2) >/tmp/blob' This pipe is writing the checksums to stderr to not interfere with stdout. You can redirect the hash to a file if you want to keep it. cat blob | tee >(md5sum >blob.md5) | <your pipe>
checksum a pipeline
1,435,844,238,000
I have a huge number of images from which I'd like to feed some to ffmpeg time to time. But I only want to feed ones that are alphabetically after certain image (last frame of previous run, name stored in some file). Can I for example find out an order/index number of that one file and then do head/tail using that num...
After sorting, some sed or awk could be used to match from pattern until the end of the stream. I assume that your final ffmpeg command accepts a list of file arguments. I use a printf instead of ffmpeg below. find . -type f -print0 | sort -z | sed -nz '/pattern/,$p' | xargs -r0 printf '%s\n' GNU arguments separation...
Filtering file list to show only files alphabetically after certain file
1,435,844,238,000
I am trying to create a BASH script that will run a command, filter the output of that command and then read the results of that output to then print only sections that meet the given requirement. For example: I have managed to reduce the output of the original command so that the output looks like this: Profile: 1 Ps...
You can use sed with an N;D scheme: sed -n 'N;s/PsA\( of Profile \([0-9]*\): \)[^0].*\nPsL\1[^0].*/\2/p;D' The N appends the next line, so you always have two in the pattern space. Then you simply define a pattern with both values of the same profile and a number that does not start with zero (so values with leading ...
BASH Script - Reading output and cutting by value
1,435,844,238,000
I am running MacOS(really BSD), and I want to redirect certain traffic over an ssh tunnel using a a local forward. Seems easy enough, but I am repeatedly blocked by the ambiguous "/etc/pf.conf:29: syntax error" message at every turn. I must have gone through 30 iterations of the rule by now. Additionally, I have re...
You can do it : rdr pass quick on $ext_inf inet proto tcp from any to any port 1394 -> $target port 1394
macos - local port redirection using pfctl and syntax errors
1,435,844,238,000
I am unable to launch Gnome System Log Viewer after setting some filters. This is so, even after rebooting and reinstalling this GUI program. I found the following relevant line in /var/log/messages: kernel - [ 2345.123456] traps: logview[1234] trap int3 ip:32682504e9 sp:7fff9123c150 error:0 It seems to be some ex...
The filter settings are saved as a gsettings scheme: org.gnome.gnome-system-log.filters. You can edit them with dconf-editor (org>gnome>gnome-system-log>filters). Replace the space in the name of the filter with a dash (or some other character), and gnome-system-log will work again.
Unable to launch Gnome System Log Viewer after setting filters
1,435,844,238,000
So I'm extremely new to rsyslog (recently switch from syslog-ng) and I really like that I can have dynamic filenames... My work has recently started using docker and they're sending a lot of fields in the syslogtag to a remote host. So instead of setting up filters for every instance, I'm trying to write a dynamic fil...
I am not an expert, but you can start with this: you will need to repeat your regexp (I don't know how you can evaluate a template to get the **NO MATCH** string). For example, say your "appname" part is matched by the regexp [a-z]+:, then you can write $template nomatch,"/var/log/docker/nomatch/%hostname%.log" if (n...
rsyslog7 filter to hostname if no match to regex
1,435,844,238,000
I was wondering how to filter a table with several columns based on a specific value in each of the columns of interest. I have this example here: Chr1 16644 0 0 1 1 Chr1 16645 0 0 1 1 Chr1 16646 0 0 1 1 Chr1 16647 0 0 ...
As @Devon mentioned in the comments: Use || instead of &&. The reason is that you want show lines where at least one of the columns 3,4,5,6 is different then zero. Here's another way to understand it. You're trying to remove lines where those columns are all zeros. Let's begin with the other way around: print all the ...
How to filter a table using awk
1,435,844,238,000
I got a command foo that outputs a list of files separated by a new line. How can I filter those files by their content using regex, and output the filtered files list?
If your system has GNU xargs, you could do something like foo | xargs -d '\n' grep -l regex
Filter a list of files by content
1,435,844,238,000
I have a file containing full path names of files an directories. From this list I would like to filter out any pathnames that reference directories so that I am left with a list containing only file paths. Can anybody think of an elegant solution?
while IFS= read -r file; do [ -d "$file" ] || printf '%s\n' "$file" done <input_file Would print the files that are not determined to be of type directory (or symlink to directory). It would leave all other type of files (regular, symlink (except to directories), sockets, pipes...) and those for which the type cann...
Filter directories from list of files and directories
1,435,844,238,000
I have a large file that needs to be filtered by the first field (which is never repeated). Example as below: NC_056429.1_398 2 3 0.333333 0.333333 0.333333 0.941178 NC_056429.1_1199 2 0 0.333333 0.333333 0.333333 0.941178 NC_056442.1_7754500 0 3 0.800003 0.199997 0.000000 0.0...
Don't try to do this by matching regular expressions. Instead, use _ or space as awk's field separator so you have the chromosome and positions in easy to use variables: start=1234567 end=7654321 awk -v s="$start" -v e="$end" -F '[ _]' '$3 >= s && $3 <= e' file.txt > cut_file.txt Also, avoid using CAPS for variable ...
How to use variables (that change in loop) in awk statement to cut a file
1,435,844,238,000
I have two files file1: U 20 100 1_A 1_A U 14 200 1_B 1_B U 14 300 1_C 1_C file2: D 12 90 1_A 1_A D 15 97 1_A 1_A D 16 99.5 1_A 1_A D 9 111 1_A 1_A D 71 200 1_B 1_B D 88 198 1_B 1_B D 12 210...
Use just awk without need of a shell-loop: awk 'NR==FNR{ col4[$4]=$3; next } (-1< col4[$4]-$3 && col4[$4]-$3 <1) { print $1, $2, $3, $5 }' file1 file2 you should check if the substraction result of two numbers are within (-1,1) exclusively rather than adding ±1 to third column value and comparing with its pair. If ...
Filtering a file based on values from another file
1,636,736,061,000
I want to filter a file for lines starting with a space. I use the following command: grep -v "^ " < input > input_no_starting_space To double check my results, I run the following: grep "^ " < input > double_check and then count the number of lines in input_no_starting_space and double_check to see whether their su...
May be, your input_file do not contains only text data. Try to use grep with -a option. See also --binary-files=TYPE option for grep command and man grep first paragraph about data enconding and NULL value: If a file's data or metadata indicate that the file contains binary data, assume that the file is of type TYPE....
grep -v does not return complement of grep
1,636,736,061,000
I had question about IPtables. Let's start with this example of my book: What rules you would set for a mail server accepting connections for EMSTP (port 465) and IMAP (port 993) having a network interface eth1 exposed to the Internet and another network interface eth2 exposed to the corporate network? I tried...
First, some reminders: -p argument is to specificy protocols like TCP, UDP, ICMP ... not higher level protocol like IMAP. OUTPUT and INPUT chains are for the packets outgoing from the machine and incoming to the machine. If you want to filter packets that are forwarded (when your machine act as a gateway), you must ...
Iptable order of rules with example
1,636,736,061,000
I have a binary that I will be running multiple times in parallel, each instance executed with different input from the command line. I wanted htop to list only these processes so that I can compare the usage of memory based on the cli inputs. I tried [htop -p ] but this lists only one process even if I give muliple ...
From man htop: F4, \ Incremental process filtering: type in part of a process command line and only processes whose names match will be shown. To cancel filtering, enter the Filter option again and press Esc. So, once you start htop, type \test and press Enter to filter in only commands contai...
htop - See/Filter all the instances of a binary
1,636,736,061,000
I am dealing with datasets on xml files; which have the following structure: <?xml version="1.0" standalone="yes"?> <exper> <entry> <Source /> <Status>pass</Status> <Title>S2</Title> </entry> <entry> <Source /> <Status>fail</Status> <Title>S1</Title> </entry> <entry> <Source /> ...
1) Install xmlstarlet https://sourceforge.net/projects/xmlstar/files/xmlstarlet/1.6.1/ 2) Process XML documents from command line: xmlstarlet sel -t -v "//Title" -n input.xml The output: S2 S1 S3
Easy way to filter xml files in a visual way
1,636,736,061,000
I have a big file with many columns and rows, looks like: A B C D E F1 F2 F3 F4 F5 a1 b1 c1 d1 e1 0 0 1 0 1 a2 b2 c2 d2 e2 1 0 0 1 1 a3 b3 c3 d3 e3 1 1 0 0 1 .... The A, B, C, D, E columns contain some information, and F1-5 columns represent some ids. The 0s or 1s mean absence/presenc...
AWK solution: awk 'NR==1{ split($0,h); columns=sprintf("%s %s %s %s %s",h[1],h[2],h[3],h[4],h[5]); next } { for (i=6;i<=NF;i++) if ($i) { if (!a[h[i]]++) print columns > h[i]".txt"; print $1,$2,$3,$4,$5 > h[i]".txt" } }' file split($0,h) - split th...
Filter rows with a specific header name and containing "1" in a column
1,636,736,061,000
I have 3 files: list_file, file1, and file2. I want to extract entire lines from file1 and file2 based on a list_file pairwise and concatenate the results on output. Namely, I need to extract only lines from file1 and file2 with names on 4th column matching names on first and second column of list_file (respectively),...
Using GNU awk for ARGIND: $ awk ' ARGIND<3 { a[ARGIND,$4]=$0; next } ((1,$1) in a) && ((2,$2) in a) { print a[1,$1], a[2,$2] } ' file1 file2 list_file ut1A 25598 47989 uth1.g20066 ut1B 16951 39342 uth2.g18511 ut1A 40324 40617 uth1.g3149 ut1B 31677 31970 uth2.g22348 If you don't hav...
Filtering lines of two files based on a third list file
1,636,736,061,000
I am writing an Ansible playbook that grants and rejects access to some dirs. Base is a list of user dictionaries: users: - {name: 'user1', dirs: ['dir1', 'dir2']} - {name: 'user2', dirs: ['dir1', 'dir3']} - {name: 'user3', dirs: []} As a helper fact, I created a list of all dirs occurring in any of the user r...
Use filter difference. For example - set_fact: users_all: "{{ users|json_query('[].name') }}" - set_fact: dirs_forbidden: "{{ dirs_forbidden|default([]) + [ {(item.keys()|list|first): (users_all|difference(item.values()|list|first))}] }}" loop: "{{ dirs_allowed }}" ...
Ansible - negative filter question
1,636,736,061,000
I can discard lpr default filters using the -l (or -o raw) option. But how can I list them ? (FWIW I'm using lpr from cups-client 1:2.2.6-15.fc28, Fedora.)
This is not the most satisfying solution, but setting LogLevel info in /etc/cups/cupsd.conf (then restarting CUPS e.g. with sudo systemctl restart cups), the filters are listed in CUPS logs when a job is sent. CUPS logs being handled by journald by default in Fedora (28, at least), they can be accessed by $ journalct...
How can I list default lpr filters?
1,636,736,061,000
I tried to filter my log file by the functionality For example: 195.xx.x.x - - [13/Apr/2017:09:60:xx +0200] "POST /userx/index.php?m=contacts&xxxx... 192.xx.x.x - - [13/Apr/2017:09:45:xx +0200] "POST /userx/index.php?m=customer&xxxx... 197.xx.x.x - - [13/Apr/2017:09:10:xx +0200] "POST /userx/index.php?m=meeting&xxxx.....
sed '/\//!{H;d};G;/m=\(.*\)\n.*\1/d;P;d' file log Explanation: First read file with the filter keywords, then the logfile. Lines containing no / are interpreted to be keywords and appended to the hold space (H). Other lines get the hold space appended (G) and are deleted if the keyword after the m= is repeated in the...
Filter a log file
1,636,736,061,000
This is what I am trying to do: I have a server using Postfix on a Ubuntu precise 64bits and I have a table list of emails in /etc/postfix/virtual, like this: [email protected] [email protected] [email protected] [email protected] Now I want to put a filter that get all mails sent and add some prefix to the subject ...
You can use mimedefang configured as smtpd_milter with postfix. It can change/add/delete headers (action_change_header/action_insert_header/action_delete_header) and append text (append_text_boilerplate) to the mails. More info here
Create a Filter for Postfix on Virtual Mails
1,636,736,061,000
How do I search in a textfile with grep for the occurrence of a word or another word? I want to filter the apache log file for all lines including "bot" or "spider" cat /var/log/apache2/access.log|grep -i spider shows only the lines including "spider", but how do I add "bot"?
use classic regex: grep -i 'spider\|bot' or extended regex (or even perl regex -P): grep -Ei 'spider|bot' or multiple literal patterns (faster than a regular expression): grep -Fi -e 'spider' -e 'bot'
Use grep with or [duplicate]
1,636,736,061,000
I use the following command successfully rsync -e 'ssh' -avr [email protected]:/home/mikrotik /bck/mikrotik/ How can I add date filter to this command? I would like to sync only files that are newer than n days from remote dir [email protected]:/home/mikrotik to local dir /bck/mikrotik/
Unless you intentionally delete files periodically from /bck/mikrotik that are still present on the source system, or you have many thousands of files and you're seeing a time impact while rsync skips the files it's already transferred, your date filter shouldn't be necessary. However, having said that you can use fin...
Rsync with date filter over ssh
1,636,736,061,000
I have log.txt with sample output like these: ... 10-Feb-2022 15:15:14.099 lorem 10-Feb-2022 15:15:15.133 ipsum 10-Feb-2022 15:15:16.233 dolor ... I expect the output of filtered log.txt will be ... 1644480914 lorem 1644480915 ipsum 1644480916 dolor ... I have figured out how to convert date string to timestamp date...
Your date command seems to allow for the -d option to convey a date/time. Try like cut -d' ' -f-2 file | date +%s -f- | paste -d' ' - file | cut -d' ' -f1,4- 1644502514 lorem 1644502515 ipsum 1644502516 dolor It cuts the date/time fields from the input, feeds them to the date command via the -f (read DATEFILE) option...
date string column to timestamp column in a log file
1,636,736,061,000
I have a question about a problem that I have to solve, I have my lines in this way: Input GTEX-1117F-0003-SM-58Q7G GTEX-1117F-0003-SM-5DWSB GTEX-111CU-0826-SM-5EGIJ GTEX-111CU-0926-SM-5EGIK GTEX-ZZPU-2726-SM-5NQ8O GTEX-ZZPU-2626-SM-5E45Y K-562-SM-2AXVE K-562-SM-26GMQ I have another file that tells me that the first ...
I will give a different sample so the count is more visible: GTEX-1117F-0003-SM-58Q7G GTEX-1117F-0003-SM-58Q7G GTEX-1117F-0003-SM-5DWSB GTEX-111CU-0826-SM-5EGIJ GTEX-111CU-0926-SM-5EGIK GTEX-ZZPU-2726-SM-5NQ8O GTEX-ZZPU-2626-SM-5E45Y K-562-SM-2AXVE The command, assuming the patient id is in the format string-string: ...
reading and discarding lines
1,636,736,061,000
I'm trying to figure this out. How does the Ansible IP Addr filter work, this always seems to return False $ ansible -m debug -a 'msg={{"www.google.com"|ipv4}}' 10.1.38.15 10.1.38.15 | SUCCESS => { "msg": false }
The ipv4 filter is not a name resolution filter. It simply tests if the passed string is a valid IPv4 address. If you want to resolve a DNS address you probably should be using the lookup plugin 'dig'. https://docs.ansible.com/ansible/latest/plugins/lookup/dig.html Example $ ansible localhost -m debug \ -a 'msg={{...
Ansible hostname resolution with ipaddr filter returns False?
1,636,736,061,000
I have a file where I want to grep for an md5 hash. I was able to do that but how can I display the match to stdout? When I do grep -e "[0-9a-f]\{32\}" file I just get: Binary file file matches. Is there a way to print the result to stdout?
From https://www.gnu.org/software/grep/manual/html_node/Usage.html Why does grep report “Binary file matches”? If grep listed all matching “lines” from a binary file, it would probably generate output > that is not useful, and it might even muck up your display. So GNU grep suppresses output > from files that appear ...
grep for pattern
1,636,736,061,000
as a newbie to linux kernel and all the commands, I am reaching out to you guys, hoping you can help me solve my issue. When running the next command sudo dmidecode -t 5 I get the following output: # dmidecode 3.0 Getting SMBIOS data from sysfs. SMBIOS 2.4 present. Handle 0x0084, DMI type 5, 46 bytes Memory Controlle...
This will list the supported speeds: dmidecode | awk '/^\t[^\t]/ { speeds = 0 }; /^\tSupported Speeds:/ { speeds = 1 } /^\t\t/ && speeds' This works by matching lines as follows: lines starting with a single tab mean that we’re not expecting speeds; lines starting with a single tab followed by “Supported Speeds:” me...
Filter dmidecode memory controller for supported speeds
1,636,736,061,000
Extend of this question: How to combine strings from JSON values, keeping only part of the string? Above link's output also include the "name" of folder type, need to exclude these "type": "date_added": "13170994909893393", "date_modified": "13184204204228233", "id": "2098", ...
Given an array of objects, jq can select the ones that fulfil a certain criteria using select(). It sounds like you may want to use .array[] | select(.type == "url") Given a JSON document like { "array": [ { "type": "folder", "name": "example folder" }, { "type": "url", "name": "example url" } ] } ...
jq: parse json file with constraint from other field [duplicate]
1,636,736,061,000
I'd like to filter an input like this foo 2022-11-11 foo 2022-12-11 something else bar 2022-12-07 to obtain foo 2022-11-11 bar 2022-12-07 I'm starting with grep -oP "^[A-z]{3}" | sort -u but of course this will not print the full line.
I suggest to take only from first column to first column (-k 1,1) into consideration: grep -E '^[[:alpha:]]{3} ' | sort -k 1,1 -u Output: bar 2022-12-07 foo 2022-11-11
grep unique results but show full line containing the match
1,636,736,061,000
I have some files in a folder. By running the following command I can create a list with the filtered filenames ( test1, test2,test3) and pass it using xargs to a grep filtering command filter file in the command contains a few values to be filtered out. ls -Art1 | grep test | xargs -L1 grep -vf filter > ouput Howeve...
There's no need to pipe the output of ls to search for a name match. Just use a shell glob. This also allows you to define an output file for each filter attempt for file in *test* do [ -f "./$file" ] && grep -vf filter "./$file" >"${file}_output" done Technically this is potentially a slightly different set of f...
Passing value with xargs to generate dynamic output filename
1,636,736,061,000
So I have files that need to remove/move/filter. All files have this pattern like this in a directory, let's say directory frames contain this pattern filename timestamp_in_nanosecond.jpg. And this is sample of that files with using pipelined tail from ls. ls | tail. (I'm using tail because ls too slow, maybe because ...
Use a wildcard mv 1660649147?????????.jpg frames2/ Depending on whether or not you mean to include the upper limit, maybe also mv 1660649148000000000.jpg frames2/ If there are too many files for the wildcard to match without running out of buffer space, use find instead: find . -name 'frames2' -prune -o -name '16606...
Remove/move files in a directory with filename timestamp pattern
1,658,821,946,000
Sorry if this is a basic question, I don't use linux often but I have a 13GB file that I want to filter down. I have 123 columns and I want to remove rows that have only a . in the 75th column. I've been looking into how to do this, at the moment I've got: awk '$75 !~/./ {print $0}' oldfile.txt > newfile.txt Am I alo...
try awk '$75 != "." ' oldfile.txt > newfile.txt this will match 75 th column for an extact dot. what you did awk '$75 !~/./ {print $0}' will try to match 75th column for something different from any char (regexp match by . ) more precisely awk '$75 ~ /./ ' will match any row where 75th columen have at least one ch...
How to filter rows by one column?
1,658,821,946,000
Suppose I have log.txt The sample of log.txt are like these format: Code Data Timestamp ... C:57 hello 1644498429 C:56 world 1644498430 C:57 water 1644498433 ... If I want filter string line that contain C:57 I can achieve it with cat log.txt | grep C:57 then I redirect output to the new file hence cat log.txt | grep...
You can use tail -f thusly: tail -f log.txt|grep C:57 >> filtered_log.txt This continuously reads log.txt grepping for the token C:57 and adding any matches to the filtered.log.txt. The use of cat to read the log and pipe that to grep is a useless use of cat. grep can directly read a file. You're wasting I/O by combi...
Filter changing file periodically and redirect filtered output to new file
1,658,821,946,000
I want to sync all *.sh files in exactly one sub directory. I tried this cmd but all files in a directory are synced instead of only particular file types. rsync -vr -n --include="*.sh" --exclude="*/*/" --prune-empty-dirs /source /target I also tried adding a filter like --filter="+ *.sh" but this did not change the...
Your examples don't seem to match your description. I think what you are saying you want is this, match all the *.sh files in an unknown subdirectory immediately underneath your /home put the files in the unknown subdirectory on the target do not include /home in the destination path Looking from /home, this command...
rsync only particular file types in subdirectories with a fixed maximum depth
1,658,821,946,000
I'm trying to use the following command to extract a time period forthe current day date and grep for the specific message as you can see below: awk -v date="$(date +%Y%m%d')" '$1="date" && $3>"180000" && $3<"192000"' /app/exploit/log/FILE_send.log | grep "End success file transfer /app/reception/FILENAME.dat to HOSTX...
You can use the command: awk -F'[-|]' -v date="20190405" '$1 == date && $2>180000 && $2<192000' file_name | grep "End success file transfer /app/reception/FILENAME.dat to HOSTX" The output of awk command will be: 20190405 - 180050 | INFO | FILE_SEND.sh | | FILENAME.dat | 18004983070...
awk filtering one column log file
1,658,821,946,000
With html bookmark saved from chrome or others, frequently exported as html file that comes with <a href tag that I'd like to filter and arrange: <a href="https://<a-web-site>">Title of the website</a> How to use basic linux's util like sed/grep/awk to filter and arrange items like: Title of the website https://<a-we...
With sed: $ echo '<a href="https://<a-web-site>">Title of the website</a>' | sed -e 's|.*href="\(.*\)".*>\(.*\)</a>|\2 \1|g' Title of the website https://<a-web-site>
Filter on html tag
1,658,821,946,000
I'd like to parse incoming mail with custom script. Something which would be easily done with man aliases(5) for real users or with procmail for vitual users. But on my system is is plesk and setup is: virtual_transport = plesk_virtual, thus I cannot put configure it as virtual_transport = procmail. What is plesk_virt...
OK, at least I've found that plesk_virtual is an external delivery method, defined in /etc/postfix/master.cf: plesk_virtual unix - n n - - pipe flags=DORhu user=popuser:popuser argv=/usr/lib64/plesk-9.0/postfix-local -f ${sender} -d ${recipient} -p /var/qmail/mailnames Thus it's a binary /usr/lib64/plesk-9.0/postfix-...
Mail processing with custom script on Postfix and Plesk (plesk_virtual)
1,658,821,946,000
I am building a wordlist which will contain words like error,fail,kill,warn,out of,over,too.....etc. so that I can filter tons of logs for issues within seconds using grep. Especially, it's for digging linux logs. Found 1: https://github.com/cornet/ccze static char *words_bad[] = { "warn", "restart", "exit", "stop...
Shell wrapper with wordlist grepbad() { grep --color=always -i "warn\|restart\|exit\|stop\|end\|shutting\|down\|close\|\ unreach\|can't\|cannot\|skip\|deny\|disable\|ignored\|\ miss\|oops\|not\|backdoor\|blocking\|ignoring\|\ unable\|readonly\|offline\|terminate\|empty\|virus" $* } grepgood() { grep --color=alw...
searching logs for failures using grep with wordlist?
1,658,821,946,000
I have a program that returns some content every time I run it. Some of that content may have already shown during the last run. foo bar baz and on next execution it might show two "old lines" and one "new line": bar baz house Is it possible to filter out and save previously unseen content of these commands to a fil...
If you have sponge from the moreutils package installed: $ printf '%s\n' foo bar baz > log # first call $ printf '%s\n' bar baz house | grep -v -F -x -f log | sponge -a log # subsequent calls $ cat log foo bar baz house
Save "unseen" output of command to file
1,658,821,946,000
All I need is the Zip file name. In the first step I searched for the author: egrep -ni -B1 --color "$autor: test_autor" file_search_v1.log > result1.log whatever worked, the result was: zip: /var/www/dir_de/html/dir1/dir2/7890971.zip author: test_autor zip: /var/www/dir_de/html/dir1/dir2/10567581.zip author: ...
grep -B1 "$autor: test_autor" file_search_v1.log | grep -o "[^/]*\.zip$" Change the first grep as needed. The second grep filters out the parts at the end of the line containing non-/ characters followed by the .zip suffix. If you know that your zip files only contains digits, you could exchange [^/] with [[:digit:]]...
grep with filter grep, how?
1,658,821,946,000
I have a file.txt (it does not have the same number of columns for each row): e.g. 1 21:10 21:23 2 1:94 1:100 1:123 3 14:1 14:60 14:23 I have another file (file2.txt) that contains 4 columns (separated with " ") a 21 20 60 b 2 80 90 c 14 50 100 d 2 10 20 e 14 1 12 I want to check the initial part for each row of...
Assuming you mean <= instead of < since 1<1<12 is not YES: $ cat tst.awk NR==FNR { cnt[$2]++ beg[$2,cnt[$2]] = $3 end[$2,cnt[$2]] = $4 next } { out = "" for (i=2; i<=NF; i++) { split($i,parts,/:/) key = parts[1] for (j=1; j<=cnt[key]; j++) { if ( (beg[key,j] ...
Filtering a .txt file using a regular expression and a second file
1,658,821,946,000
I have a list of directories similar to the below in a .txt file /Season_1/101 /Season_1/101/Thumbnails /Season_1/101/Thumbnails/Branded /Season_1/101/massive_screengrabs /Season_1/102/massive_screengrab /Season_1/102/thumbnails /Season_1/102/thumbnails/Branded /Season_1/103/Thumbnails /ARCHIVE/480x360 v6/Season 2 /AR...
The following command will work with text files that do not contain blank lines. If you need to accommodate blank lines some modification would be required. cat textfile | sort | awk 'BEGIN { FS="/" }; { if ( NR == 1 || $0 !~ lastField ) { print $0; lastField = $NF } }' > newtextfile Where textfile is your text file a...
Filter directory list text file based on the short common root directory
1,658,821,946,000
I try to filter my log file by request. I want to filter all the request(that you can find on the 7th column:/userx/index...) that have (m=xxx and a=xxx) or (m=xxx and doajax=xxx) and only have the request with those parameters For example: 192.xx.x.x - - [11/Apr/2017:09:59:xx +0200] "POST /userx/index.php?m=xxxx&do...
what's wrong with awk '( $7 ~ /m=xxx/ ) && (( $7 ~ /a=xxx ) || ( $7 ~ /doajax=xxx/ )) { split($7,A,"&") ; $7 = A[1] "&" A[2] ;print ;} ' logfile where && stand for logical and, || logical or, split($7,A,"&") will split 7-th field into array, using & as separator, $7 = A[1] "&" A[2] change (not in file) 7-th fiel...
filter a log file by request
1,658,821,946,000
Is there any distribution with a built in solution for web content filtering for my network?
Ubuntu has Squid in it's repository which is easy to configure. I do believe other distros have it as well. https://help.ubuntu.com/lts/serverguide/squid.html
Linux Distrib with build in Web filter solution
1,658,821,946,000
I am having the following problem in linux: I need to find specific files from a directory and copy those files (if they exist) into another directory this is the command (i need to find specific text files starting with the word log) and only take the last 10 recent ones; the command works find /mydir -type f -name '...
I would use xargs to copy all files. You can pipe the output to xargs which executes cp to all passed arguments. The Wikipedia article describes xargs better than I could do and you could look into the manpage of Linux. A call that does what you want could be: find /mydir -type f -name 'log*.txt' | tail -n 10 | xargs ...
How to combine find and cp in linux to copy specific files
1,658,821,946,000
Currently I have the following bash script that gets the width and height of all the files in the directory: ls | cat -n | while read n f; do width=$(identify -format "%w" "$f") height=$(identify -format "%h" "$f") echo "$width , $height" done How can I only get the height/width of files where the filename end...
for filename in *-example99.jpg do width=$(identify -format "%w" "$filename") height=$(identify -format "%h" "$filename") done
bash filter the file names by regex or similar in a while loop
1,658,821,946,000
I want to filter any comma and any double quote mark from output by some command with. For some entries. Pseudocode: removechar --any -, -" Current output could look like any of these lorem, ipsum " dolor ," ",,lorem,, ipsum ,,, """ dolor "," ,lorem ipsum ,,, """ dolor , Desired output: lorem ipsum dolor lorem ips...
You could use tr: <input tr -d ',"' >output or, to remove the comma and quote characters and squeeze adjacent spaces (as shown in your desired output) <input tr -d ',"' | tr -s ' ' >output or more generally to remove all punctuation and squeeze all horizontal whitespace <input tr -d '[:punct:]' | tr -s '[:blank:]' >...
How to strip characters by argument?
1,658,821,946,000
I am struggling over a filter where I am trying to trim data in a specific column of a CSV after the 3rd or nth occurrence of the character \. My data looks something like this: data,data,c:\path1\folder2\folder3\folder4\...,data,data,data data,data,c:\path1\folder2\folder3\folder4\...,data,data,data data,data,c:\path...
awk -F "\\" '{gsub(/\.*,/,",",$0);print $1"\\"$2"\\"$3"\\"$4$NF}' file.txt data,data,c:\path1\folder2\folder3,data,data,data data,data,c:\path1\folder2\folder3,data,data,data data,data,c:\path1\folder2\folder3,data,data,data data,data,c:\path1\folder2\folder3,data,data,data Python #!/usr/bin/python import re qw=re.c...
Trim pathname in CSV file
1,658,821,946,000
I have a csv file and I need to filter it out into two files based on whether the last column contains the word "ecDNA". I already have two more copies of the file to edit without changing the original file. Is there any way I can delete all the lines that do not contain "ecDNA" from one file and only retain lines tha...
awk -F, '$NF ~ /ecDNA/' oldfile > newfile NF is the number of fields (columns) on the current input line, so $NF is the value (contents) of the last field. If $NF contains "ecDNA", then print the the line. Otherwise, ignore it. If you need the match to be case-insensitive (and you're using GNU awk), use: awk -F, -...
How to compile lines with a certain word in the last column into a separate file?
1,658,821,946,000
I am able to get the file difference using git diff command and I got it filtered like below: -This folder contains common database scripts. +This folder contains common database scripts. + + + +New Line added. However I want to be able to get only the difference that is the line New Line added. how can I achieve th...
Try This: If +New Line added. is the last line of the output of git diff: git diff | tail -1 | tr -d '\n' If you want to get rid of + git diff | tail -1 | sed -e 's/^+//' | tr -d '\n'
Filter the below text using shell commands
1,297,916,768,000
I want to run a java command once for every match of ls | grep pattern -. In this case, I think I could do find pattern -exec java MyProg '{}' \; but I'm curious about the general case - is there an easy way to say "run a command once for every line of standard input"? (In fish or bash.)
That's what xargs does. ... | xargs command
Execute a command once per line of piped input?
1,297,916,768,000
In Fish when you start typing, autocompletion automatically shows the first autocompleted guess on the line itself. In zsh you have to hit tab, and it shows the autocompletion below. Is there anyway to make zsh behave more like fish in this regard? (I am using Oh My Zsh...)
I have implemented a zsh-autosuggestions plugin. It should integrate nicely with zsh-history-substring-search and zsh-syntax-highlighting which are features ported from fish.
How to make zsh completion show the first guess on the same line (like fish's)?
1,297,916,768,000
I have recently come across a file whose name begins with the character '♫'. I wanted to copy this file, feed it into ffmpeg, and reference it in various other ways in the terminal. I usually auto-complete weird filenames but this fails as I cannot even type the first letter. I don't want to switch to the mouse to per...
If the first character of file name is printable but neither alphanumeric nor whitespace you can use [[:punct:]] glob operator: $ ls *.txt f1.txt f2.txt ♫abc.txt $ ls [[:punct:]]*.txt ♫abc.txt
Dealing with file names with special first characters (ex. ♫)
1,297,916,768,000
bash and fish scripts are not compatible, but I would like to have a file that defines some some environment variables to be initialized by both bash and fish. My proposed solution is defining a ~/.env file that would contain the list of environment variables like so: PATH="$HOME/bin:$PATH" FOO="bar" I could then jus...
bash has special syntax for setting environment variables, while fish uses a builtin. I would suggest writing your .env file like so: setenv VAR1 val1 setenv VAR2 val2 and then defining setenv appropriately in the respective shells. In bash (e.g. .bashrc): function setenv() { export "$1=$2"; } . ~/.env In fish (e.g....
Share environment variables between bash and fish
1,297,916,768,000
At the moment I need to set the fish shell to be my default shell on NixOS and there is no official documentation on how to do that declaratively (not by running chsh) in NixOS.
In your configuration.nix, { pkgs, ... }: { ... programs.fish.enable = true; users.users.<myusername> = { ... shell = pkgs.fish; ... }; } Followed by nixos-rebuild switch. More info in NixOS Wiki.
How to change the default shell in NixOS?
1,297,916,768,000
Using Bash I've often done things like cd /study && ls -la I understand that the double ampersand is telling the terminal don't execute part two of this command unless part one completes without errors. My question is, Having just moved to the Fish shell and trying the same command I get an error stating I can't use &...
Instead of &&, which doesn't exist in fish, use ; and the command and: cd /study; and ls -la According to the fish tutorial: Unlike other shells, fish does not have special syntax like && or || to combine commands. Instead it has commands and, or, and not.
Run a command only if the previous command was successful in Fish (like && in bash)
1,297,916,768,000
Is there a way I can do something like run myscript.sh in fish ? I am using Arch Linux, and have installed the fish shell together with oh-my-fish Can someone tell me which file I must edit to add my custom shell startup commands? In zsh it was the ~/.zshrc file. What is it in the fish shell? I have a problem: if I pu...
I tried sourcing .profile on fish startup and it worked like a charm for me. just do : echo 'source ~/.profile;clear;' > ~/.config/fish/config.fish Quit terminal or iterm2 followed by firing up an alias from .profile to test.
How to edit the fish shell startup script?
1,297,916,768,000
I created a directory d and a file f inside it. I then gave myself only read permissions on that directory. I understand this should mean I can list the files (e.g. here), but I can't. will@wrmpb /p/t/permissions> ls -al total 0 drwxr-xr-x 3 will wheel 102 4 Oct 08:30 . drwxrwxrwt 16 root wheel 544 4 Oct 08:3...
Some preparations, just to make sure that ls does not try more things than it should: $ unalias ls 2>/dev/null $ unset -f ls $ unset CLICOLOR Demonstration of the r directory permission: $ ls -ld d dr-------- 3 ccorn ccorn 102 4 Okt 14:35 d $ ls d f $ ls -l d ls: f: Permission denied $ ls -F d ls: f: Permission d...
Why can't I list a directory with read permissions?
1,297,916,768,000
I do not know why, but after making a whole bunch of fish aliases. I'm assuming I have neglected one simple step after assigning them all but I cannot seem find the solution myself. Can anyone lend me a hand? Thank you very much! ~Ev
It basically boiled down to: Open ~/.config/fish/config.fish in your favorite editor. If it's not already there, it'll make it for you. (Don't su it though.) Add all the aliases you want. It'll save them and always load then because this is apparently Fish's version of bashrc. Save it, baby! Enjoy.
Fish-Shell Will Not Save my Aliases
1,297,916,768,000
I have fish installed in my Linux Mint DE. I really like how fish makes things easier and it looks so pretty although I haven't find a correct answer about why I can't execute: sudo: !!: command not found At first I tried to escape the exclamation signs with sudo !! but didn't work either. Does someone know why is th...
I haven't found a inbuilt replacement for !! in Fish however you can write a function that allows you to keep using !! Taken from this answer https://superuser.com/a/719538/226822 function sudo --description "Replacement for Bash 'sudo !!' command to run last command using sudo." if test "$argv" = !! echo ...
fish: sudo: !!: command not found
1,297,916,768,000
While using fish as my shell, i'm trying to set permissions on a bunch of c source files in current dir with find . -type f -name "*.c" -exec chmod 644 {} +; I get an error find: missing argument to `-exec' or find . -type f -name "*.c" -exec chmod 644 {} \; I get an error chmod: cannot access '': No such file...
fish happens to be one of the few shells where that {} needs to be quoted. So, with that shell, you need: find . -type f -name '*.c' -exec chmod 644 '{}' + When not quoted, {} expands to an empty argument, so the command becomes the same as: find . -type f -name '*.c' -exec chmod 644 '' + And find complains about th...
find -exec not working in fish
1,297,916,768,000
I'm a bash user, starting a new job at a place where people use fish shell. I'm looking at the history command which I often use in bash. When I use it in fish I get a long list of my history which I can scroll up and down on with the arrow keys. There are no numbers like in bash and pressing enter is the same as the...
The history command in the fish shell isn't bash-compatible, it's just displaying it in a pager (e.g. less). To select an old command, you'll probably want to enter the part you remember right into the commandline, press up-arrow until you have found what you want and then press enter to execute. E.g. on my system I e...
How does history work in fish shell?
1,297,916,768,000
On an Ubuntu ($ uname -a : Linux kumanaku 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux), I just installed fish ($ fish --version : fish, version 2.7.1) using the following commands : sudo apt-add-repository ppa:fish-shell/release-2 sudo apt-get update sudo apt-get install...
You need a shebang line if the executable file cannot be run natively by the kernel. The kernel can only run machine code in a specific format (ELF on most Unix variants), or sometimes other formats (e.g. on Linux you can register executable formats through binfmt_misc). If the executable file needs an interpreter the...
fish shell : exec format error
1,297,916,768,000
I have an array whose elements may contain spaces: set ASD "a" "b c" "d" How can I convert this array to a single string of comma-separated values? # what I want: "a,b c,d" So far the closest I could get was converting the array to a string and then replacing all the spaces. The problem is that this only works if th...
Since fish 2.3.0 you can use the string builtin: string join ',' $ASD The rest of this answer applies to older versions of fish. One option is to use variable catenation: echo -s ,$ASD This adds an extra comma to the beginning. If you want to remove it, you can use cut: echo -s ,$ASD | cut -b 2- For completeness, ...
In the Fish shell, how can I join an array with a custom separator?
1,297,916,768,000
Is there an equivalent of POSIX shells' set -x or set -o xtrace that cause the shell to display the commands being run in the fish shell?
Since fish 3.1.0, the fish_trace variable makes this functionality available: > set fish_trace on; isatty; set -e fish_trace ++ source share/fish/functions/isatty.fish ++++ function isatty -d 'Tests if a file descriptor is a tty' + isatty +++ set -l options h/help +++ argparse -n isatty h/help -- +++ if +++ set -q _fl...
xtrace equivalent in the fish shell
1,297,916,768,000
In bash, if I run kill %1, it kills a backgrounded command in the current shell (the most recent one, I believe). Is there an equivalent of this in fish? I haven't been able to find it online in a bit of web searching. I'm not sure if I did it wrong, but $ ps PID TTY TIME CMD 73911 pts/5 00:00:00 fis...
Your command has worked, but because the job is stopped it has not responded to the signal. From your example where it didn't seem to work, try continuing the process with fg or bg, or forcibly terminate the process with kill -SIGKILL %1, and it will exit. kill %1 works immediately in bash and zsh because it is a buil...
kill %1 equivalent in fish
1,297,916,768,000
I want to be able to check if a fish shell is being run in login, interactive, or batch mode, and this question only discusses bash.
Use the status command: $ fish -c 'status --is-interactive; and echo yes; or echo no' no $ status --is-interactive; and echo yes; or echo no yes Also, status --is-login. That should cover your bases.
How can I check if a shell is login/interactive/batch in fish?
1,297,916,768,000
I'd like to always run a fish script in the background even if the user doesn't specify that. In bash, this can be done by surrounding the script with ( at the start and ) & at the end. Is there anyway for a fish script to run itself in the background?
fish does not fork to execute subshells, so it is not yet possible to run fish script in the background - see https://github.com/fish-shell/fish-shell/issues/563 A hackish workaround is to invoke fish again, like so: #!/usr/local/bin/fish fish -c 'sleep 5 ; echo done' &
Run fish script in background? [closed]
1,297,916,768,000
In bash, I usually do grep -f <(command) ... (I pick grep just for example) to mimic a file input. What is the equivalent in fish shell? I cannot find it in the documentation.
The <() and >() constructs are known as "process substitution". I don't use fish, but according to its documentation, it doesn't directly support this: Subshells, command substitution and process substitution are strongly related. fish only supports command substitution, the others can be achieved either using a bloc...
Bash's Process Substitution "<(command)" equivalent in fish shell
1,297,916,768,000
I would have assumed that following examples work perfectly fine. $ which -a python python3 pip | xargs -I {} {} --version No '{}' such file or folder $ which -a python python3 pip | xargs -I _ _ --version No '_' such file or folder $ which -a python python3 pip | xargs -I py py --version No 'py' such file or folder ...
In xargs -I replstr utility arguments, POSIX requires that the replstr be only substituted in the arguments, not utility. GNU xargs is compliant in that regard (busybox xargs is not). To work around it, you can use env as the utility: which -a ... | xargs -I cmd xargs env cmd --version (chokes on leading whitespace, ...
xargs | Use input as command
1,297,916,768,000
In bash I could either do echo -e "a\tb" or echo a$'\t'b. How do you do this in fish?
\t, without quotes. Same thing for other control characters (\n for a newline, etc.).
Print tab character in fish
1,297,916,768,000
I want to use FISH shell. But I've read FISH is not a POSIX shell so setting it to default shell by chsh is not recommended. What I want is whenever I start xfce4-terminal I would like to start FISH shell instead of bash. Adding exec fish to .bashrc seems to be a solution, but I want a to know if there is a way to sta...
Yes, sure. Run: xfce4-terminal --preferences And make: Run a custom command instead of my shell and type fish in the box just below. That's it, close and start xfc4-terminal. That's it. Enjoy.
How can I make xfce4-terminal start fish shell?
1,297,916,768,000
If I run fish from a bash prompt, it will inherit the environment variables I have set in my .bashrc and .profile files, including the important $PATH variable. So far so good. Now, I want xfce4-terminal, my terminal emulator, to use fish instead of bash. I found that it supports a -e command line parameter for that b...
When bash is run as a non-interactive shell it will not source the .bashrc file and if you use a graphical display manager then the login shell used to run the GUI launcher commands might not have sourced the .profile file. Thus, commands run using the GUI launcher might not have the desired environment variables set ...
How do I create a GUI application launcher for xfce4-terminal with fish but inheriting the environment variables from bash?
1,297,916,768,000
I often find myself wanting to move a file, then create a symlink where it was. In doing this by hand I tend to twist my mind. (Esp after doing half a dozen files) Use cases: Moving all my "dot files" to a folder so i can version control them Moving a file onto a faster disk (scratch) for High Performance Computing ...
function lnmv set dest_dir $argv[1] set files $argv[2..-1] for f in $files set dest $dest_dir/$f mv -- $f $dest and ln -s -- $dest $f end end
Is there a command to move a file, and symlink it back to where it was?
1,297,916,768,000
I'm trying to get the CLI password manager pass to work in my fish shell with auto completion. I've already found the necessary file, yet am having trouble finding out where to put it, or rather getting it to work. So far I've added it to: ~/.config/fish/pass.fish ~/.config/fish/completions/pass.fish and added the co...
The second option listed (~/.config/fish/completions/pass.fish) is the preferred approach. The third should also work. I tried the following: Put the file at ~/.config/fish/completions/pass.fish Type pass followed by a space Hit tab And I see completions from that file. It's possible that fish is looking somewhere e...
Adding pass completion to fish shell
1,297,916,768,000
I use the fish shell and would like to be able to "source" some shell scripts written with sh-compatible syntax, which fish cannot read. For example lots of software expects you to source some shell scripts to export helpful environment variables: # customvars.sh FOOBAR=qwerty export FOOBAR If I don't care about pres...
For the specific problem of having scripts in POSIX-compatible shell language that set environment variables and wanting to use them in fish, one existing solution is Bass. It is a script that works similarly to terdon's answer but can handle more corner cases.
Is it possible to exec some commands in a subshell without immediately exiting afterwards?
1,297,916,768,000
I would like tab completion to behave differently when the cursor is at the beginning of a word than when the cursor is at the end of a word. I've only ever seen shells that tab-complete the suffix, like this: $ tiff2␣ tiff2bw tiff2pdf tiff2ps tiff2rgba However, sometimes I would also like to tab-complete the...
Zsh does this provided that you enable the “new-style completion system” and turn on the complete_in_word option. autoload -U compinit; compinit setopt complete_in_word After that, you can press Tab anywhere in a word, including at the beginning, and you'll get completion proposals for the middle of the word (for the...
Shell that tab-completes prefix?
1,297,916,768,000
I use fish as my standard shell. And I use sudo sometimes. But I'm having problems with credential caching. On an Ubuntu system, this works: niklas@Niklas-Mobil~> sudo true [sudo] password for niklas: niklas@Niklas-Mobil~> sudo true niklas@Niklas-Mobil~> On a Debian system, this doesn't work: niklas@ThinServer ~> sud...
Edit your /etc/sudoers, add this line (or edit if it's existed): Defaults !tty_tickets fish somehow thinks command is from separated session. It's maybe due to tty's modification date as reported by stat is changing under fish. This was caused by fish's futimes() call See more details: fish issue #122 Disable futime...
sudo and fish: no credential caching
1,297,916,768,000
In bash it's possible to do my_function() { echo "hello" | #remove 'l' tr -d 'l' } but in fish ( http://fishshell.com ) I wasn't able to do the same: function my_function echo "hello" | \ # remove 'l' tr -d 'l' end I've tried with backslash at the end of the comment too but no luck. I tend to use thi...
It's impossible because of the bug reported at https://github.com/fish-shell/fish-shell/issues/983. However, there are works on real fish grammar (as opposed to quick hacky parser) in ast branch of fish-shell repository (now merged, but disabled by default). Currently, there is no patch to support this syntax, but it'...
Is it possible to have comments in multiline commands in fish?
1,297,916,768,000
I'm trying to improve the performance of my fish prompt, and since my prompt includes my current git branch, I'm wondering if there may be a way to make it faster. Right now I'm using git symbolic-ref HEAD | sed 's/refs\/heads\///', and when I first cd into a git repo, it sometimes hangs for a little while. I'm wonder...
git symbolic-ref HEAD is as far as I know the fastest method, it basically just opens .git/HEAD and some config files (/etc/gitconfig, $HOME/.gitconfig and .git/config). If you are sure that the delay is caused by the git command it is probably due to some io delay. If you want a faster method you have to read .git/HE...
What's the fastest (CPU time) way to get my current git branch?