New answers tagged

1

It seems that cryptsetup requires the LUKS header to be either regular file or device. If you need to provide the LUKS header as an output from a process/stream, you can easily circumvent the restriction by sending it to /dev/ram cat LUKS-HEADER > /dev/ram0 (provided that your kernel supports ramdisk) Then you can then simply use your cryptsetup ...


2

If you want to globally redirect everything that happens to be written (like you do now), it's tricky, but can be hacked together. I strongly recommend that, if it's possible, just do it by normal piping. just wrap everything you do in a subshell. In this case ( echo "this is the message" other stuff ) | cat or just write everything into a variable ...


1

simple case: output="$(echo "here is a message")" # [...] echo "$output" Not so simple if you have to read from a redirection and cannot use a pipeline like echo "$output" | while IFS= read -r line; do :; done You can use a FIFO and a background process: mkfifo fifo echo "$output" >fifo & while IFS= read -r line; do :; done <fifo tee ...


1

libtrash is broken: For example, in helpers.c: char* make_absolute_path_from_dirfd_relpath(int dirfd, const char *arg_pathname) { char *abs_path = NULL; if (arg_pathname == NULL) { return NULL; } else if (arg_pathname[0] == '/' || dirfd == AT_FDCWD) { return arg_pathname; } else if (dirfd <= 0) { errno = ...


0

Command piping you can use anywhere you feel that output of first command can be fed as input to next. Examples. With text files you can pass the text file to grep to find particular lines of text. Then you can pass the output to sed or awk to modify or print certain part of line. cat example txt | grep {some_line} | awk {some_command} Working with ...


0

Pipes work best with filters and translators find /usr/bin/ | #produce sed 's:.*/::' | #translate: strip directory part grep -i '^z' | #filter : select items starting with z xargs -d '\n' aFinalConsumer #consume This way, the data can flow from one program to the next one bufferful and at no point ...


0

execute this one in any directory you want have an sorted analyse for folder size (then scroll down with END key): du -m| sort -n| less Sortiert nach Ordnergrösse


0

wc … > ~/log.info | cut ~/log.info | … The two sides of the pipe are executed in parallel. Unless wc is especially quick to finish and cut is especially slow to start, by the time cut reads ~/log.info, it's likely to be still empty, or even nonexistent. To compound the problem, the redirection on sort is also executed in parallel and also truncates ...


2

The name of the output file is always the original name with the extension changed (unless you specify something other with command switches) so you could do this instead of piping. tex file.tex; dvips file.dvi; ps2pdf file.ps This executes the commands one after the other. I don't think the tex command has any way of outputting the result of its ...


0

How about: perl -e 'print sort map {s/(\d).*(\w)\..*//r} <>' (Needs perl 5.14+ - this is probably installed on your system already) Uses an inlined bit of perl code that: reads <> which is STDIN or files specified on command line. Uses a substitution regex which captures a digit (\d) and a letter just before a . (\w)\. then returns the ...


0

You can strip out all of the bits you don't want by piping the output through sed: wc -l ~location/folder/folder/*.log > ~/log.info cut -d "/" -f9 ~/log.info | sort | sed 's_/.*/__;s_\.log$__'


1

if multiline (9 lines) solution is ok, check below hextail.sh script: #!/usr/bin/env bash #par1==buffsize, par2=xxd-columns-width, par3=sleepVal; defaults: 256 16 0 size=${1:-256}; cols=${2:-16}; cnt=0; hbuff=$(eval printf '00%.0s' {1..$size}) while true; do hbuff=${hbuff:2}$(dd bs=1 count=1 2>/dev/null | xxd -p) #shiftLeft, add 1b printf ...


2

getreport cannot read from the terminal because it is a background process. man 2 read: EIO : I/O error. This will happen for example when the process is in a background process group, tries to read from its controlling terminal, and either it is ignoring or blocking SIGTTIN or its process group is orphaned. I guess what you want is not possible ...


0

Performance is complicated. The only way to be sure is to benchmark on a real system with a real load. Piping multiple utilities definitely has a cost. Compared with string operations, this cost is very high. However, if the amount of data is large enough, a pipe solution can be faster, because it may allow specialized tools to do their job faster and it ...


2

Sometimes it is just easier to profile things: I've created a sample input file: aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc field:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc shell script 'a.sh': #!/bin/bash for i in `seq 1 1000`; do cat test.dat | grep ^field | head -n1 | sed ...


11

Your pipe commands, as a non-terminal destination, are buffering your output. It will show up eventually, but only when quite a lot of output builds up or the ping command exits. You can use ping -c 5 google.com to set a specific number of packets to be sent and then ping will exit. Your output comes back and the pipes should work as expected. Edit: ...


2

The process substitution rawtopng <(tail myfile) fileout creates a pipe (just like tail myfile | rawtopng - fileout), and passes a name for the pipe to the program. On Linux, rawtopng will see a name like /dev/fd/42, and if it queries the file type, it'll be told that it's a pipe. No write to the filesystem is required (this is an anonymous pipe, not a ...


1

I think you're on the right track! <(tail myfile) will create an Anonymous Named Pipe, and is a type of Bash Process Substitution. Normally, this will pass /dev/fd/XX as the "filename", which is a file descriptor interface to the running process. From the examples in the linked documentation: bash$ wc <(cat /usr/share/dict/linux.words) 483523 ...


0

You can create a named pipe. Do something like mkfifo input to create the pipe. Start the program that you want to read the output of, and redirect the output to the pipe, aka myprog > input Then run your other command with input as the file. Note that pipes are one directional. The program will be able to read, but not to write.


0

Here grade is in 5th column of file, so following awk will give you expected results: awk -F, 'toupper($5)=="C"' input.csv


2

POSIXly: tr -s '[:blank:]' '[\n*]' <file | grep '^[[:lower:]]*$'


1

Here you are: sed 's/[^A-Za-z]\+/\n/g;s/$/\n/;s/[^\n]*[A-Z][^\n]*\n//g;s/\n$//' <input_file | sort -u


2

screen -dmS workspace; screen -S workspace -X stuff $'ps aux > output-x\n' I first create a detached session with the -d switch, I called my session workspace. I then send my command to the same session with -X stuff, I am using $'', but you could also use double quotes, but have to do a control M instead of a \n, which I don't like so I normally use ...


0

You can use the disown or nohup usage: How to monitor WGET download progress after closing SSH session


0

Try this with your tailing whitespace in your file: awk -F, '/,C.*$/ {print}' file Output: 001,A B,78,23,C


0

I found that this works on Solaris. (time ls) &> file


0

You could try something like less $(ls -ctr | tail - 1) (the $(...) isn't universal, you might need to substitute backticks). Change less to taste.


5

You want to use the xargs command: $ ls -ctr | tail -1 | xargs cat This will take the STDOUT of the tail -1 command, and instead of using it as STDIN for the cat command will use it as options to the cat command.


1

Using UnZip 6.00 of 20 April 2009, I was able to do this: $ date | zip jeff.zip - $ unzip -l jeff.zip Archive: jeff.zip Length Date Time Name --------- ---------- ----- ---- 29 01-21-2016 13:02 - --------- ------- 29 1 file $ unzip -p jeff.zip | cat Thu Jan 21 13:02:31 EST 2016 $ ...


0

You could pipe direct to gzip, then redirect compressed data to a file: echo "my not compacted data" | gzip > compact.gz


-1

sed has an option for that : -u, --unbuffered Which loads minimal amounts of data from the input files and flushes the output buffers more often. See man sed for more details.


17

Take a look at the POSIX specification for the write() function: The write() function shall fail if: … An attempt is made to write to a pipe or FIFO that is not open for reading by any process, or that only has one end open. A SIGPIPE signal shall also be sent to the thread. So the sequence of events is: The head process exits. This causes all ...


26

It depends on the OS buffers and the timing between the 10th and 11th writes of dmesg. After head writes 10 lines, it terminates and dmesg will receive SIGPIPE signal if it continues writing to the pipe. Depending on your OS buffer, dmesg will often write more than 10 lines before head consumes them. To see that head had consumed more than 10 lines, you ...


3

head closes stdin after printing 10 lines. Then dmesg detects that the stdout is closed and exits. To be more precise, dmesg will receive the EPIPE error from the write call to stdout. From the dmesg.c source code here: https://github.com/karelzak/util-linux/blob/v2.27.1/sys-utils/dmesg.c#L654-L659 rc = fwrite(p, 1, len, out) != len; if (rc != 0) { if ...


0

It is a matter of which shell we are talking about. On this shell, I get: $ times 0m9.805s 0m3.372s 39m29.072s 0m15.537s Because it has been running for a while. However, a sub-shell will report zero: $ ( times ) 0m0.000s 0m0.000s 0m0.000s 0m0.000s And, as a pipeline is executed in a sub-shell for each part of it: $ sleep 10 | times 0m0.000s 0m0.000s ...


3

Within a pipeline, all commands are run in a subshell. times reports time spent by the shell and its subshells, but not its parent shell. You can try process substitution instead: times > >( head -n1 ) times > >( read user sys ; echo $user )


4

The idiom >(...) just means (in layman terms): "the name of a file". And it works as a "name of a file" (sort of, all will be clear in an instant): $ echo <(date) /proc/self/fd/11 Or some other number/name on your OS. But echo does print a name, exactly as if you do: $ echo ProcSubs11 ProcSubs11 And if a file with the label ProcSubs11 exists, ...


4

it seems operationally no different from a simple unnamed pipe. The point is that not every software may support reading from stdin or writing to stdout. Furthermore if you want input from several processes then you cannot tell them apart (without looking at the data itself) with just a pipe: { echo foo; echo bar; } | cat # vs. cat <(echo foo) ...


0

Old question, but in case someone comes across it as I did: My solution is to read with a timeout. while read -t 5 line; do echo "$line" done If stdin is empty, this will return after 5 seconds. Otherwise it will read all the input and you can process it as needed.


1

This can be done easily with a couple of common utilities: cut -d : -f 1 input.txt | uniq cut extracts fields from the input file. -d denotes the delimiter character (in this case a :), and -f 1 says to extract the first field. uniq removes repeated adjacent lines from the input


0

Since all of my results had the same format (The file's were in the src/ directory) I was able to use the following command: cat input.txt | tr ':' '\n' | grep 'src/' | uniq


0

Use: cmp -s \ <(flac --silent --decode --force-raw-format --sign=signed --endian=little "$1" --stdout) \ <(flac --silent --decode --force-raw-format --sign=signed --endian=little "$2" --stdout)


0

Thanks to the ideas from comments and other sources I was finally able to write this code and answer my own question: inputStream | awk -F'\t' -v OFS="\t" '{ if ( col1 == ""){ for (i=1;i<=NF;i++){ if ($i == "BlueId"){ col1=i; } else if ($i ...


0

You could do something like: # get the header line from the file and split each header to a different line header=$(head -1 $file_name | tr ' ' '\n') # get the index/line number of the blueID blueID_index=$(echo "$header" | grep -n "blueID" | sed 's/:.*//') # same for whiteID whiteID_index=$(echo "$header" | grep -n "whiteID" | sed 's/:.*//') # now ...



Top 50 recent answers are included