![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
mydata > mydata
yes > yes no > no mydata > mydata no > yes yes > no mydata > mydata no > yes yes > no mydata > mydata yes > yes no > no |
|
#3
|
|||
|
|||
|
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
|
|
#4
|
|||
|
|||
|
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! |
|
#5
|
|||
|
|||
|
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
|
|
#6
|
|||
|
|||
|
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! |
|
#7
|
|||
|
|||
|
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.
|
|||
| Google The UNIX and Linux Forums |