The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to reverse the contents of a file? aajan UNIX for Advanced & Expert Users 10 05-17-2008 08:03 AM
how to arrange 3 file to one using awk...? penyu Shell Programming and Scripting 9 01-17-2008 02:26 AM
Need to read a file in reverse scorreg Shell Programming and Scripting 5 03-01-2006 09:14 PM
sort a file in reverse order frustrated1 Shell Programming and Scripting 11 09-21-2005 12:41 PM
reverse lookup file problem Westy564 IP Networking 2 01-09-2004 11:55 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-12-2007
Registered User
 

Join Date: Mar 2007
Posts: 17
Reverse Arrange File

I've got hundreds of lines in a file that looks like this:

Line1 CCR CCH
Line2 ICVM FBO GSC
Line3 MKF

The result should be like the one below so that I can insert them on our database.

Line1 CCR
Line1 CCH
Line2 ICVM
Line2 FBO
Line2 GSC
Line3 MKF

Thanks in advance!
Reply With Quote
Forum Sponsor
  #2  
Old 06-12-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
Code:
nawk '{ for(i=2;i<=NF;i++) print $1, $i }' myFile
Reply With Quote
  #3  
Old 06-12-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
do something like the following to get just the list of words

Code:
cat input-file | while read N
do
    for d in $N
    do
         echo $d
    done
done
then run the output through sort.
Reply With Quote
  #4  
Old 06-12-2007
Registered User
 

Join Date: Mar 2007
Posts: 17
Quote:
Originally Posted by vgersh99
Code:
nawk '{ for(i=2;i<=NF;i++) print $1, $i }' myFile
It worked!!! I removed the "n" on the "nawk". Some users maybe confused.
Code:
awk '{ for(i=2;i<=NF;i++) print $1, $i }' myFile
Reply With Quote
  #5  
Old 06-13-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,275
nawk is the "usable" version of awk on Solaris, vgersh works on Solaris I believe. awk on Solaris is an ancient version and does play well with everyone else's awk.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:05 PM.


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