Due to my lack of experience with script language, (shame for a Mac user) I have referred to several sources: link seemed resolved with ls *.extension | xargs -n 1 tail -n +2

This didn't for me, even after adding > merged.txt at the end, nor the following:

for f in *.txt
    tail -n +2 $f >> /path/to/some/dir/with/files/file_name

I also tried sed -e'1d' $FILE in replacement of the tail command. Didn't work.

tail -n +2 file_name.extension, cat LIN_1994-11_0100.txt | tail -n +2, awk 'FNR != 1' *.extension has no effect to the file.

I am uncertain if this has anything to do with the current issue. Or whether the link is related to the issue.

If anyone could find the reason for this problem or way out of it..would be majorly grateful. I have transferred this issue from another community here to receive more insight if I could.

  • 1
    So basically you want to combine several text files into one, without the first line of each file, right? Unless the file is empty I can't see a reason why tail -n +2 FILENAME shouldn't produce a copy of FILENAME without the first line on stdout. What kind of result do you get when running this (take a short file so you can see the result easily)? – nohillside Jan 16 '18 at 18:31
  • Yes the header is the same for all all of the text files, so I intended to keep it for the first file and then remove for the rest. I get no copy file. I get nothing when I type tail -n +2 FILENAME. It doesn't produce error message, and the file is left untouched. (including the date modified) – dia Jan 16 '18 at 18:34
  • cd; (echo foo; echo bar; echo zot) > FILENAME; tail -n +2 FILENAME works for me – thrig Jan 16 '18 at 18:38
  • Are foo, bar, zot here..different file names? (e.g. 3 out of the 264 I have) If I use this command it seems I would only be able to remove the first line of the merged, not the first line of each files that I want to combine. – dia Jan 16 '18 at 18:41
  • tail -n+2 /path/to/*.txt > /path/to/file_name might be simpler, and would even sneak in a header for each file found. Said header can be omitted with -q. – DopeGhoti Jan 16 '18 at 18:44

The stated assertion that tail does not work on Macs is faulty, as shown (line breaks an indentations added to for loops for clarity):

$ for i in {1..3}; do 
    for file in foo bar; do 
      echo "$i  $file" >> $file
$ paste foo bar
1  foo  1  bar
2  foo  2  bar
3  foo  3  bar
$ tail -n+2 -q * > output
$ cat output
2  bar
3  bar
2  foo
3  foo
$ uname -a
Darwin recacted-hostname 17.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64

Answer originally found as edit to the question itself:

The issue was with the file format!! mac2unix changed the files so that tail command works! And link for those who might have the same problem in the future. Thank you for all your interest and input!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.