V
V
Vladimir2019-03-29 15:05:16
bash
Vladimir, 2019-03-29 15:05:16

How to write lines from stdin to the beginning and end of the file using the cat command, no more than two times?

There is a file one, it is necessary to write a random number of lines into it (write to the beginning and end of the file, without losing the original lines already contained there).
This must be done with the CAT command, and use it no more than 2 times. The strings themselves must be taken from standard input (example: cat - >> one )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2019-03-29
@saboteur_kiev

cat "файл_с_рандомными_строками_в_начало" "оригинальный_файл" "файл_с_рандомными_строками_в_конец"> temp
cat temp > "оригинальный_файл"

For example
$ echo "string3" > file.txt
$ cat - file.txt - > temp.txt
string1
string2
*** НАЖАТЬ CTRL+d для завершения ввода строк которые пойдут в начало файла
string4
string5
*** НАЖАТЬ CTRL+d для завершения ввода строк которые пойдут в конец файла
$ cat temp.txt > file.txt
$ cat file.txt
string1
string2
string3
string4
$

R
res2001, 2019-03-29
@res2001

With the first cat write the lines from stdin to a temporary file, with the second cat form the final file:
cat tmpfile one tmpfile>two

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question