How to delete row from text file?

Microsoft Excel: What is the EASIEST way to merge several delimited text files while ignoring all 1st row (headers) below the first master file?

  • And by easiest, I don't mean shelling out $80 for Bulk File Merger.  Is there other freeware or some simple code to merge several text files at once?

  • Answer:

Darshan Markandaiah at Quora Visit the source

Was this solution helpful to you?

Other answers

In Bash, if you're using Unix, Linux, or Mac, or Windows with cygwin: #!/bin/bash cat "$1" for file in `seq 2 $#`; do awk 'NR>1' < "$file" done Execute it as ./scriptname master.txt file1.txt file2.txt > output.txt.

Brendan Shillingford

Given the wording of the question, I assume you want to keep the header only from the master file, and include the data from that file and all the other files. Without knowing how you want data to be merged (can we assume the headers are the same for all the files or something?), here's a simple implementation in Python: master_file = "tmp1.txt" # the "master" file? other_files = ["tmp2.txt"] # the rest output_file = "out.txt" # the merged file # copy of the master file file_in = open(master_file, 'r') file_out = open(output_file, 'w') info = file_in.read() file_in.close() file_out.write(info) file_out.write('\n') # process other files for f in other_files: # remove header first_line = True file_in = open(f, 'r') for line in file_in: if first_line: first_line = False continue file_out.write(line) file_out.write('\n') file_in.close() file_out.close()

Shine Wang

You have marked Microsoft Excel topic as the primary topic, therefore I am assuming you want a Microsoft solution. I do not know if this is a one-off exercise or regular one, so makes it hard to recommend the best solution. For simplicity sake, let's assume this is a one-off exercise with ability to repeat (if needed). I have written some high level steps below. Should you require more detail, this can be added in later. 1. Open Microsoft Excel 2. Begin recording a macro: http://office.microsoft.com/en-gb/word-help/record-or-run-a-macro-HA010099769.aspx 3. Open the first file in Microsoft Excel. 4. Edit the first file as required. For example retain the headers. 5. Save this file as "Master". 6. Open the next file. Copy the required data to the master file. 7. Close second file. 8. Highlight column A. Use the text to columns function to split the data into columns. http://support.microsoft.com/kb/214261 9. Stop recording macro. 10. View the macro code by opening the macro in Visual Studio (short cut key ALT +F11). 11. Now modify the code accordingly - such as looping through steps 6 & 7. Appreciate some coding and manual effort is required here, however the recorded code could be tailored to repeat this process.

James Lancaster

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.