If the top and bottom are fixed, it can be something like:
cat top.txt /dev/stdin bottom.txt > text.txt
# with cat, - works the same as /dev/stdin
or
{
echo 123 #top.txt
cat
echo 456 #bottom.txt
} > text.txt
followed by your compilation commands
cat top.txt /dev/stdin bottom.txt > text.txt
gcc whatever
The first line should be a shebang line specifying your interpreter, unless you're OK with /bin/sh
#!/bin/bash
cat top.txt /dev/stdin bottom.txt > text.txt
gcc whatever
If you then mark the script executable with chmod +x the_script
,
./the_script
will be equivalent to /bin/bash ./the_script
.
If you want the scrip to abort a command fails, start it with set -e
(or make the shebang line (#!/bin/bash -e
).
Edit:
cat
expects a whole file (until you enter ctr-d -- the end of file marker). If you want just one line, you can do read -r something; printf '%s\n' "$something" or head -n1
.
You can read the help pages of the commands with man $command
or help $command
.
bash
builtinread
and the-n
flag for echo. But take a look atsed
and rethink your concept as loading your phrase into a variable, say$NEW
, and then runningsed 's/123456/123'"$NEW"'456'
Which probably has it own issues, especially if$NEW
gets a slash inside it, but its a first step. – infixed May 24 '16 at 15:34