Find the answer to your Linux question:
Results 1 to 4 of 4
Hello Everyone, I have a problem that I am having a hard time finding an answer to. I have 2 files that I need to make into one file with ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75

    Text Placement

    Hello Everyone,

    I have a problem that I am having a hard time finding an answer to. I have 2 files that I need to make into one file with proper formatting.

    I am trying to match the SID number in file one with the SID number in file two. To then make my result. The files are below.

    File one looks like:
    Code:
    File #1 
    SID517091       ACCTID00267    SERVER1\Backup of files on data\admin001        07/09/08 18:32  07/09/08 18:59  1225        527532559
    SID517088       ACCTID00267    SERVER1\Backup of files on users\admin001         07/09/08 18:30  07/09/08 19:42  2335    2688906909
    SID517089       ACCTID00267    SERVER1\Backup of SQL Server\admin001        07/09/08 18:30  07/09/08 18:30  4       110759
    File #2:
    Code:
    SID517091       ACCTID00267    Closing socket           ECN1073741929 2        1215647978
    SID517091       ACCTID00267    Established socket connection    ECN1073741928 2        1215646375
    SID517091       ACCTID00267    There is not enough space on the disk.  (\SERVER1\data)
    SID517091       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517091       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    Closing socket           
    SID517088       ACCTID00267    Established socket connection
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517089       ACCTID00267    Closing socket
    SID517089       ACCTID00267    Established socket connection
    Result:

    Code:
    SID517091       ACCTID00267    SERVER1\Backup of files on data\admin001        07/09/08 18:32  07/09/08 18:59  1225        527532559
    Messages:
    SID517091       ACCTID00267    Closing socket           ECN1073741929 2        1215647978
    SID517091       ACCTID00267    Established socket connection    ECN1073741928 2        1215646375
    SID517091       ACCTID00267    There is not enough space on the disk.  (\SERVER1\data)
    SID517091       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517091       ACCTID00267    The process cannot access the file because it is being used by another process.
    
    SID517088       ACCTID00267    SERVER1\Backup of files on users\admin001         07/09/08 18:30  07/09/08 19:42  2335    2688906909
    Messages:
    SID517088       ACCTID00267    Closing socket           
    SID517088       ACCTID00267    Established socket connection
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    SID517088       ACCTID00267    The process cannot access the file because it is being used by another process.
    
    SID517089       ACCTID00267    SERVER1\Backup of SQL Server\admin001        07/09/08 18:30  07/09/08 18:30  4       110759
    Messages:
    SID517089       ACCTID00267    Closing socket
    SID517089       ACCTID00267    Established socket connection
    I tried various sed and a awk statement with no luck. Any help would be greatly appreciated.

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Code:
    awk 'NR == FNR { 
      _[$1] = $0 
      next 
      }
    _[$1] { 
      printf "%s\nMessages:\n", 
        (FNR == 1 ? "" : RS) _[$1]
      delete _[$1] 
      }1' file1 file2

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    Perfect!

    What does this mean:
    Code:
    _[$1]
    I don't understand the _

  4. #4
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    It's the array name, you can change it if you wish ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...