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
sorting/arrangement problem Abhishek Ghose Shell Programming and Scripting 7 05-25-2007 06:19 AM
Help on file arrangement kharen11 UNIX for Dummies Questions & Answers 5 03-10-2007 10:31 PM
Data arrangement bobo UNIX for Dummies Questions & Answers 6 09-21-2006 07:36 AM
Data arrangement bobo UNIX for Dummies Questions & Answers 4 08-18-2006 07:02 AM
Text file arrangement merry susana UNIX for Dummies Questions & Answers 8 06-17-2005 01:11 AM

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

Join Date: Jan 2006
Posts: 145
Angry Cell arrangement

I have a data file with hundreds of lines: I want to place a YES right below the line that say mydata....can someone please help! on the left is my the original data on the right the data format need to be:

left > Right

mydata > mydata
yes > yesno > no
mydata > mydata
no > yesyes > no
mydata > mydata
no > yesyes > no
mydata > mydata
yes > yesno > no
Reply With Quote
Forum Sponsor
  #2  
Old 08-18-2006
Registered User
 

Join Date: Jan 2006
Posts: 145
Unhappy

mydata > mydata
yes > yes
no > no
mydata > mydata
no > yes
yes > no
mydata > mydata
no > yes
yes > no
mydata > mydata
yes > yes
no > no
Reply With Quote
  #3  
Old 08-18-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Your request is a little confusing but if you want the second output you can use this hack:
Code:
nawk '
    !/^[(yes|no)]/ {print}
    /^[(yes|no)]/ {
        sub (/yesno/, "yes\nno")
        sub (/yesyes/, "yes\nyes")
        sub (/noyes/, "no\nyes")
        sub (/nono/, "no\nno")
        print
    }' file.txt
Reply With Quote
  #4  
Old 08-18-2006
Registered User
 

Join Date: Jan 2006
Posts: 145
Unhappy

Sorry for the confusion! This is what I am ask ing for:

Data file contain the following information (1000 line or more)

mydata1
abc YES
dcf NO
mydata2
dcf NO
abc YES
mydata3
dcf NO
abc YES

I need it to have the following format:

mydata1
abc YES
dcf NO
mydata2
abc YES
dcf NO
mydata3
abc YES
dcf NO

Please let me know if you can help!
Reply With Quote
  #5  
Old 08-20-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
see if this works

Assuming there are 2 lines after every occurence of pattern.
Code:
awk '/mydata/ {orig=$0; getline;one=$0;getline;two=$0; if( one ~ "YES") {printf("%s\n%s\n%s\n",orig,one,two)} else {printf("%s\n%s\n%s\n",orig,two,one)} }' fname
Reply With Quote
  #6  
Old 08-21-2006
Registered User
 

Join Date: Jan 2006
Posts: 145
Unhappy This command is not working

and here are the message I got:

awk: syntax error near line 1
awk: illegal statement near line 1
awk: bailing out near line 1


Thanks!
Reply With Quote
  #7  
Old 08-21-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
it works for me

I use HP-UX B.11.11 and the above code works. May be it could some quotes or some other character that is causing the issue.
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 02:52 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