The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Avoid creating temporary files on editing a file in Ubuntu royalibrahim Linux 7 11-17-2007 02:57 AM
searching for content of files Aretai UNIX for Dummies Questions & Answers 19 03-09-2007 03:44 AM
Cleaning the content of log files jyotipg Shell Programming and Scripting 1 11-14-2006 11:19 PM
content need changes- many files swchee Shell Programming and Scripting 3 10-05-2006 09:29 AM
Compare the content of 2 files odogbolu98 Shell Programming and Scripting 3 09-10-2002 08:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-08-2005
Registered User
 

Join Date: May 2005
Posts: 80
Creating a tabulated file from content of 2 or more files

Hi all

I need specific fields from a file to be tabulated into a single file.
I have a file with the following :-

FIELD1 InfoA FIELD2 InfoB
FILED3 InfoC

FIELD1 InfoD FIELD2 InfoE
FIELD3 InfoF

The output I would like is as follows :-
InfoA|InfoB|InfoC
InfoD|InfoE|InfoF

Any ideas. I have though of using grep and cut to create a file for each field and then use sed to read each line and echo it into a single line, however have not been able to.

Thx

J
Reply With Quote
Forum Sponsor
  #2  
Old 08-08-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
file:
Code:
FIELD1 InfoA FIELD2 InfoB
FILED3 InfoC

FIELD1 InfoD FIELD2 InfoE
FIELD3 InfoF
result:
Code:
InfoA InfoB InfoC
InfoD InfoE InfoF
Code:
awk ' {
        if(NR % 3 == 0) {continue}        
        if(NF > 2) 
        {
                    printf("%s %s ", $2, $4)
                    continue
        }
        printf("%s\n", $2)        
      } ' filename
Reply With Quote
  #3  
Old 08-08-2005
Registered User
 

Join Date: Jul 2005
Posts: 137
Jim's code appeared to be correct, so I condensed it:
Code:
4==NF { printf "%s|%s|", $2, $4 }
2==NF { print $2 }
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0