General discussion

  • Creator
    Topic
  • #2081791

    Merging of two files using unix utilitie

    Locked

    by vaddavalli ·

    I have one static file with some tags in it. And I have one data file with the values and its position like page number, line number, column number.
    No how do I merge these to files by using unix utilities.

All Comments

  • Author
    Replies
    • #3897137

      Merging of two files using unix utilitie

      by vinnyd ·

      In reply to Merging of two files using unix utilitie

      You did not say what the resulting file should look like.
      To combine two files together you can use the copy command.

      cp sourcefile1+sourcefile2 destinationfile

      That will put the two files together in sequencial order.

      To merge them together like tags, page#, line#, column# you have to write a program to do it.

    • #3897077

      Merging of two files using unix utilitie

      by lurid ·

      In reply to Merging of two files using unix utilitie

      cat file1 >> file2
      this will append file2 to the end of file one

    • #3897051

      Merging of two files using unix utilitie

      by tyswidan ·

      In reply to Merging of two files using unix utilitie

      IJust use the simple cat utility, for example if you have fil1 ( with tags)
      and file2 ( with the data), all you have to do is:

      cat file2 >> file1
      done.

      hope that helps.

    • #3897889

      Merging of two files using unix utilitie

      by gordon ·

      In reply to Merging of two files using unix utilitie

      If the above answers your question, look no further, otherwise: Welcome to the world of hard-core unix: You need to refine your question. If the files are line-for-line ok and you just want to do a “column-merge” look at: paste -d If the tags in the first file refer to a line in the second file, then you may need to sort one (or both) files first-> get rid of duplicates (uniq) -> get rid of other stuff (cut, grep, sed) and then finally join (one of the harder commands to master). I had two files I had to merge together: One had IP addresses and printer names, the other had printer names and printer setups. I “linked” them together with the printer name, but had a lot of cleaning up to do first… Presevere, there is daylight after you master these. (My end file was 2900 bytes long, so it’s a LOT smaller than any ‘C’ program)

    • #3897693

      Merging of two files using unix utilitie

      by wcf ·

      In reply to Merging of two files using unix utilitie

      There are too many unknowns in your question for a definitive answer, but a general solution is to broaden your constraints slightly and use Perl, available on most systems. One line of code to open each file, a line or two of code to read the datafile into a hash table, and another line or 2 to scan the tag table gor tags and substitute from the hash table. This kind of problem is why Perl exists!

    • #3897625

      Merging of two files using unix utilitie

      by a_rashad ·

      In reply to Merging of two files using unix utilitie

      you need to format file1 with a config. file2 ?
      if so it is more likely to be done using a C program or a hard shell script
      look for the following tools (for , cut , echo , head , typeset and sort).
      main idea is that you will read from file2 theconfig file and place the values into variables such variables you will use to format file1 you have to sort values first then use echo to place the tags in the right places
      use spaces and “\n” for positionsing after sorting the positions

    • #3900555

      Merging of two files using unix utilitie

      by achuprinin ·

      In reply to Merging of two files using unix utilitie

      I’s unclear from your question what kind of data represent your files. If the fist file contains format information for output data from the second one and files not binary.
      Then you can use awk for making your output file. It allows using templates and may be run from command line without writing separate program file. And opposite right also. You can write program file that awk will use. The second approach is usefull when you going to make output file multiple times.

    • #3901559

      Merging of two files using unix utilitie

      by rsati ·

      In reply to Merging of two files using unix utilitie

      actually, Ur question is not clear…
      i assume that u have like this
      file 1 has
      page no column no line no
      file 2 has
      1 10 10
      if want like this
      file 3
      page no 1 column no 10 line no 10

      U can use cut and paste utility of unix andcan do that…

    • #3742400

      Merging of two files using unix utilitie

      by vaddavalli ·

      In reply to Merging of two files using unix utilitie

      This question was auto closed due to inactivity

Viewing 8 reply threads