Tag Info

New answers tagged

1

(head;tail) doesn't work in a pipeline if the tail is part of the first block consumed by head: $ seq 9|(head -n2;tail -n2) 1 2 $ seq 9000|(head -n2;tail -n2) 1 2 8999 9000 You can use gsed -u 2q as an unbuffered alternative to head -n2: $ seq 9|(gsed -u 2q;tail -n2) 1 2 8 9


0

The question is not clear on whether or not the 9999999999 is always present, or whether there can be more than one such instance in the input file. So here is a sed version which caters for all of these situations. See man sed (option -i) for in-place update of the input file. sed -n '/9999999999/{H;b n}; p; :n; ${g;s/\n//p}' file


1

Other sed solution sed -i ' /9999999999/{h;d}; # move match string in hold space $G; # append string from hold space to end s/\n$// # avoid empty line if pattern have not met ' BADINS0000001065_0000000000*


1

With awk you can do: awk ' /PATTERN/ { save = $0 ; next } { print } END { print save } ' infile > outfile where you have to replace PATTERN by the actual pattern and infile is your data file; rename those appropriately. The code works as follows: /PATTERN/ { save = $0 ; next } - if the pattern is found save this line for later use and skip ...


0

Opens both compressed and non-compressed, in chronological order. ls syslog* | tac | xargs zcat -f | less


5

For the shell command cat <file.txt: The redirection operator < causes the shell to open file.txt for reading. The shell executes the cat command, with its standard input connected to file.txt. The cat command reads from its standard input (so file.txt) and copies the content to its standard output. So the shell is the one opening the file, but the ...


-1

You're correct. While this won't matter in many situations, if the shell and the process have different permissions it can. If the process you're calling has elevated privileges (such as sudo or setuid), then it can use those privileges to open files that your shell might not be able to. $ sudo cat < /etc/shadow | wc -bash: /etc/shadow: Permission ...


0

You ask, Is there a way other than Trial & Error to find out which file formats can be merged with cat and which can't? And in a comment on another question you write, Any chance for me to tell what cat might assume as header and what not This I think is the fundamental issue: cat neither knows nor cares about the file format. It takes one or ...


1

The definition of a pipe is that data written into it is read at the other end. A pipe doesn't duplicate data. Reading on a pipe is a destructive operation. If there are two readers on a pipe, each byte will be read by only one of the readers. If you want to spy on the communication between two programs via a pipe, you can do it by inserting tee between the ...


0

You need the tr after you read the plaintext file. #!/bin/bash printf "generating random file > plaintext \n" cat -v < plaintext | tr "a-z" "b-y" > generatedtext


1

CTRL+D is meaningless here - it's just another byte. This is because your serial terminal is not configured to handle it. Specifically, you're effectively in raw-mode, or Non-Canonical Input Mode. See the -icanon flag in your stty -a output? That cinches it. Here's how POSIX describes a terminal should consider an EOF character: EOF Special character on ...


1

The EOT character does not mark the end of a file. A file can contain arbitrary bytes. Typing Ctrl+D on a terminal makes the application think that the end of the file has come. The application does not read a Ctrl+D (EOT) character, it sees an end-of-file indication. The interpretation of Ctrl+D as end-of-input character is performed by the terminal driver ...


1

There are a number of ways of redirecting a command's standard input (stdin): command <file Simple redirection: stdin will be the file command <&n Duplicate other fd: stdin will be a duplication of fd n command <<word Here doc: stdin will be the script up to word other | command Pipe: stdin comes from the output of other Since there ...


5

On systems with /dev/fd/x: cat - << E0 /dev/fd/3 3<< E3 foo bar E0 bar baz E3 That is, open the two here documents on different file descriptors. If you open them both on fd 0, of course the last open overrides the previous ones. The above would be more useful with commands like paste though. Note that zsh has the MULT_IOS feature (enabled ...


1

I have no idea where it can be usefull but: cat <<HERE qwer asdf $(cat <<ALT zxcv yuop ALT ) HERE


5

cat without any args will read its standard input (i.e. file descriptor 0) until end of file, and copy that to its standard output (i.e. file descriptor 1). cat with one or more args will try to open those args in turn as its input, and copy the data to its standard output. It ignores the standard input in that case, which is a good thing as it would become ...



Top 50 recent answers are included