Skip to main content
Correct wrong variable explanation
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77

Another possibility is awk:

awk 'NR==FNR || FNR>7' person1.txt file1.txt > result.txt

This will process first person1.txt and then file1.txt. It will print the current line if either

  • we are processing the first of the two files, where NR (the per-fileglobal line-counter) is equal to FNR, the globalper-file line counter, or
  • the per-file line-counter is larger than 7 (which will only be a limitation when processing the second file, where NR is now larger than FNR)

You even can expand this to per-file specifications of lines to be skipped:

awk -- '--skip<=0' person1.txt skip=7 file1.txt skip=4 file2.txt >result.txt

You would then simply precede each file name with a variable assignment that sets the awk variable skip to the number of lines you want to have skipped from the respective input file. The awk program checks for each processed line whether this variable, if decremented by 1, falls below zero, which would indicate that the number of lines to be skipped has been reached. The condition would then be true, and the current line printed.

Notice that the -- "end-of-options" specifier is needed because the first command of the actual program starts with a --.

Another possibility is awk:

awk 'NR==FNR || FNR>7' person1.txt file1.txt > result.txt

This will process first person1.txt and then file1.txt. It will print the current line if either

  • we are processing the first of the two files, where NR (the per-file line-counter) is equal to FNR, the global line counter, or
  • the per-file line-counter is larger than 7 (which will only be a limitation when processing the second file, where NR is now larger than FNR)

You even can expand this to per-file specifications of lines to be skipped:

awk -- '--skip<=0' person1.txt skip=7 file1.txt skip=4 file2.txt >result.txt

You would then simply precede each file name with a variable assignment that sets the awk variable skip to the number of lines you want to have skipped from the respective input file. The awk program checks for each processed line whether this variable, if decremented by 1, falls below zero, which would indicate that the number of lines to be skipped has been reached. The condition would then be true, and the current line printed.

Notice that the -- "end-of-options" specifier is needed because the first command of the actual program starts with a --.

Another possibility is awk:

awk 'NR==FNR || FNR>7' person1.txt file1.txt > result.txt

This will process first person1.txt and then file1.txt. It will print the current line if either

  • we are processing the first of the two files, where NR (the global line-counter) is equal to FNR, the per-file line counter, or
  • the per-file line-counter is larger than 7 (which will only be a limitation when processing the second file, where NR is now larger than FNR)

You even can expand this to per-file specifications of lines to be skipped:

awk -- '--skip<=0' person1.txt skip=7 file1.txt skip=4 file2.txt >result.txt

You would then simply precede each file name with a variable assignment that sets the awk variable skip to the number of lines you want to have skipped from the respective input file. The awk program checks for each processed line whether this variable, if decremented by 1, falls below zero, which would indicate that the number of lines to be skipped has been reached. The condition would then be true, and the current line printed.

Notice that the -- "end-of-options" specifier is needed because the first command of the actual program starts with a --.

Amend explanation
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77

Another possibility is awk:

awk 'NR==FNR || FNR>7' person1.txt file1.txt > result.txt

This will process first person1.txt and then file1.txt. It will print the current line if either

  • we are processing the first of the two files, where NR (the per-file line-counter) is equal to FNR, the global line counter, or
  • the per-file line-counter is larger than 7 (which will only be a limitation when processing the second file, where NR is now larger than FNR)

You even can expand this to per-file specifications of lines to be skipped:

awk -- '--skip<=0' person1.txt skip=7 file1.txt skip=4 file2.txt >result.txt

You would then simply precede each file name with a variable assignment that sets the awk variable skip to the number of lines you want to have skipped from the respective input file. The awk program checks for each processed line whether this variable, if decremented by 1, falls below zero, which would indicate that the number of lines to be skipped has been reached. The condition would then be true, and the current line printed.

Notice that the -- "end-of-options" specifier is needed because the first command of the actual program starts with a --.

Another possibility is awk:

awk 'NR==FNR || FNR>7' person1.txt file1.txt > result.txt

This will process first person1.txt and then file1.txt. It will print the current line if either

  • we are processing the first of the two files, where NR (the per-file line-counter) is equal to FNR, the global line counter, or
  • the per-file line-counter is larger than 7 (which will only be a limitation when processing the second file, where NR is now larger than FNR)

You even can expand this to per-file specifications of lines to be skipped:

awk -- '--skip<=0' person1.txt skip=7 file1.txt skip=4 file2.txt >result.txt

You would then simply precede each file name with a variable assignment that sets the awk variable skip to the number of lines you want to have skipped from the respective input file. The awk program checks for each processed line whether this variable, if decremented by 1, falls below zero, which would indicate that the number of lines to be skipped has been reached.

Notice that the -- "end-of-options" specifier is needed because the first command of the actual program starts with a --.

Another possibility is awk:

awk 'NR==FNR || FNR>7' person1.txt file1.txt > result.txt

This will process first person1.txt and then file1.txt. It will print the current line if either

  • we are processing the first of the two files, where NR (the per-file line-counter) is equal to FNR, the global line counter, or
  • the per-file line-counter is larger than 7 (which will only be a limitation when processing the second file, where NR is now larger than FNR)

You even can expand this to per-file specifications of lines to be skipped:

awk -- '--skip<=0' person1.txt skip=7 file1.txt skip=4 file2.txt >result.txt

You would then simply precede each file name with a variable assignment that sets the awk variable skip to the number of lines you want to have skipped from the respective input file. The awk program checks for each processed line whether this variable, if decremented by 1, falls below zero, which would indicate that the number of lines to be skipped has been reached. The condition would then be true, and the current line printed.

Notice that the -- "end-of-options" specifier is needed because the first command of the actual program starts with a --.

Attribution not needed. Add output file.
Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

Another possibility is awk:

awk 'NR==FNR || FNR>7' person1.txt file1.txt > result.txt

This will process first person1.txt and then file1.txt. It will print the current line if either

  • we are processing the first of the two files, where NR (the per-file line-counter) is equal to FNR, the global line counter, or
  • the per-file line-counter is larger than 7 (which will only be a limitation when processing the second file, where NR is now larger than FNR)

As noted by @Kusalananda, youYou even can expand this to per-file specifications of lines to be skipped:

awk -- '--skip<=0' person1.txt skip=7 file1.txt skip=4 file2.txt >result.txt

You would then simply precede each file name with a variable assignment that sets the awk variable skip to the number of lines you want to have skipped from the respective input file. The awk program checks for each processed line whether this variable, if decremented by 1, falls below zero, which would indicate that the number of lines to be skipped has been reached.

Notice that the -- "end-of-options" specifier is needed because the first command of the actual program starts with a --.

Another possibility is awk:

awk 'NR==FNR || FNR>7' person1.txt file1.txt > result.txt

This will process first person1.txt and then file1.txt. It will print the current line if either

  • we are processing the first of the two files, where NR (the per-file line-counter) is equal to FNR, the global line counter, or
  • the per-file line-counter is larger than 7 (which will only be a limitation when processing the second file, where NR is now larger than FNR)

As noted by @Kusalananda, you even can expand this to per-file specifications of lines to be skipped:

awk -- '--skip<=0' person1.txt skip=7 file1.txt skip=4 file2.txt

You would then simply precede each file name with a variable assignment that sets the awk variable skip to the number of lines you want to have skipped from the respective input file. The awk program checks for each processed line whether this variable, if decremented by 1, falls below zero, which would indicate that the number of lines to be skipped has been reached.

Notice that the -- "end-of-options" specifier is needed because the first command of the actual program starts with a --.

Another possibility is awk:

awk 'NR==FNR || FNR>7' person1.txt file1.txt > result.txt

This will process first person1.txt and then file1.txt. It will print the current line if either

  • we are processing the first of the two files, where NR (the per-file line-counter) is equal to FNR, the global line counter, or
  • the per-file line-counter is larger than 7 (which will only be a limitation when processing the second file, where NR is now larger than FNR)

You even can expand this to per-file specifications of lines to be skipped:

awk -- '--skip<=0' person1.txt skip=7 file1.txt skip=4 file2.txt >result.txt

You would then simply precede each file name with a variable assignment that sets the awk variable skip to the number of lines you want to have skipped from the respective input file. The awk program checks for each processed line whether this variable, if decremented by 1, falls below zero, which would indicate that the number of lines to be skipped has been reached.

Notice that the -- "end-of-options" specifier is needed because the first command of the actual program starts with a --.

Add extension of the idea to variable number of skipped lines
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77
Loading
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77
Loading