2

The following lines append the content of essay_i.txt to the end of essay1.txt:

touch essay1.txt
for (( i = 1 ; i <= 10 ; i++ )); do
sed '2p' essay_"${i}".txt >> essay1.txt
done

How should I change it so that the first line of each of essay_i.txt are not copied (i.e. only copy line 2->end) ?

userene
  • 276
user2413
  • 14,957

1 Answers1

8

To suppress the first line, use '1d' (i.e. line 1, delete):

touch essay1.txt
for file in essay_*; do
  sed '1d' $file >> essay1.txt
done

the output will be

~$ cat essay1.txt 
line 2 from essay 1
line 3 from essay 1
line 2 from essay 2
line 3 from essay 2
...

for all of the files named essay_* in the current working directory.


Instead of using sed, you can also use tail to do this job:

tail -n +2 $file >> essay1.txt

Where +2 means from the second line onwards (-n 2 would be the last two lines).