New answers tagged


To expand on the already given answers, expand can also take a list of tab stop positions. This is useful if the content lengths of the varlious columns varies a lot. I came over this requirement today when I wanted to make the output of openssl ciphers more readable: $ openssl ciphers -v 'HIGH'|tr -s ' ' '\t'|expand -t31,41,57,70,90 ...


@Thomas Dickey's answer is brilliant. I just want to add some obvious facts about the case of reading several files (loosely related to your question, but still): cat <file1 <file2 <file3 will read only file3, at least in bash. (Actually, it depends on shell, but most shells will dup every specified file to stdin, which causes the last one to ...


My first thought was the same as Jeff Schaller's: cut -c 17-64. However that includes the closing quote, so you need cut -c 17-63 If you want the first quoted word and not every word is the same length, you can use awk: awk -F\" '{print $2}' file.txt


There is no major visible difference in your test case. The most obvious one would be the error message you get if there is no file named myfile.txt in the current directory, or if you are not allowed to read it. In the former case, cat will complain and in the latter case, your shell will, clearly showing which process is trying to open the file, cat in ...


cat myfile.txt reads the file myfile.txt then prints it to the standard output. cat < myfile.txt here cat isn't given any file(s) to open, so -like many Unix commands do- reads the data from the standard input, which is directed there from file.txt by the shell, and prints to standard output.


In the first case, cat opens the file, and in the second case, the shell opens the file, passing it as cat's standard input. Technically, they could have different effects. For instance, it would be possible to have a shell implementation that was more (or less) privileged than the cat program. For that scenario, one might fail to open the file, while the ...


This is more general than bash. In POSIX shell, your EOF is referred to as a word, in the discussion of here-documents: If no characters in word are quoted, all lines of the here-document shall be expanded for parameter expansion, command substitution, and arithmetic expansion. In this case, the <backslash> in the input behaves as the ...


Within a here document there are no comment lines. man bash: No parameter and variable expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. If any characters in word are quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. If word is ...


You can use more $ cat file | more $ ./program | more It displays the output from the beginning and you can go down by pressing spacebar or return keys until you want to get. press q to quit. Also you can use a different terminal as terminator and configure it to display "n" lines as you wish.


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


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.


I found a possible solution: for f in *; do echo -e $f"\n\t$(cat $f)"; done


for f in *; do printf '%s\n' "$f" paste /dev/null - < "$f" done Would print the file name followed by its content with each line preceded by a TAB character for each file in the directory. Same with GNU awk: awk 'BEGINFILE{print FILENAME};{print "\t" $0}' ./* Or to avoid printing the name of empty files: awk 'FNR==1 {print FILENAME}; {print ...


The command cat is able to concatenate files and to print them on the standard output. When it is invoked without specifying any file or with a -, it will read the standard input. In your command it is used in both the ways. Step by step: The first part of your command (cat ~/.ssh/ does exactly what you understood: it prints the local file ...

Top 50 recent answers are included