Input file: ankit.txt with header date and trailer count
H2014-12-02
12ASDF23 FGHJ HJKL
123ASD23 FGHJ HJKL
123ASD23 FGHJ HJKL
123ASD23 FGHJ HJKL
T000004
I want data without header and trailer.
Command:
head -n -1 ankit.txt | tail -n +2 >output
in shell script
echo `head -n -1 ankit.txt | tail -n +2` >output
Iutput:
12ASDF23 FGHJ HJKL 123ASD23 FGHJ HJKL 123ASD23 FGHJ HJKL 123ASD23 FGHJ HJKL
Output coming as a single line ... (That I dont want)
I tried simply given cat command in shell script but displayed dadata is also as single line
I tried same command without echo in shell script.
even I kept 1 command to show output through shell script :
cat ankit.txt
output is a single line. wc -l is giving correct count but a simple cp is also giving a single line output.
cp ankit.txt output
Looks like you've got Windows line endings. You've got two options. Either pre-process your input file to give it UNIX endings:
or else do that as part of your pipe:
Note that
dos2unix
has two modes. In the first case, it'll take the input file and rewrite it with UNIX line endings (which is ideal for pre-processing). In the second, it'll read from stdin and write the new output to stdout (which is ideal for pipes).Using
is not only wasteful, it will also perform whitespace splitting and glob expansion on the output from
command
before passing it toecho
. Usually you simply wantor if you insist on doing a process substitution, and expect its output to be preserved, put it in double quotes:
(Notice also the switch to the modern, recommended syntax for process substitution.)
But really, why would you want that? If you really do, would it not be better still to have