The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
use variable for sed print line atchleykl UNIX for Dummies Questions & Answers 3 02-23-2009 01:49 PM
print line whatever line i want in a file... there any way kittusri9 Shell Programming and Scripting 1 05-15-2008 12:37 PM
How do i print this output all on the same line? rcon1 UNIX for Dummies Questions & Answers 1 02-05-2008 10:52 AM
awk print line Chiefos UNIX for Dummies Questions & Answers 7 06-15-2006 05:28 AM
Print file line by line handak9 Shell Programming and Scripting 2 10-20-2005 08:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-17-2008
ajp7701 ajp7701 is offline VIP Member  
Supporter
  
 

Join Date: Dec 2007
Posts: 63
awk print the next line on the current line

Ok I have a file with hundreds of lines, four columns, space delimited, TESTB.TXT for example
TESTB.TXT
---

AA ZZ 12 34
BB YY 56 78
CC XX 91 23
DD VV 45 67


---

I want a new file that has 7 columns, the first four are identical, and the next 3 are the last three of the next line...so for example
TESTB2.TXT
---

AA ZZ 12 34 YY 56 78
BB YY 56 78 XX 91 23
CC XX 91 23 VV 45 67
DD VV 45 67


---


I hope I typed that right and I hope the pattern is obvious. Obviously the last line of the file wont have a next line, so its last3 columns are blank. no problem there. or if you know of a similar script just point me to it and I'll hack out the details.
  #2 (permalink)  
Old 04-17-2008
bandaru bandaru is offline
Registered User
  
 

Join Date: Sep 2004
Posts: 12
$[/tmp] > more test.txt
AA ZZ 12 34
BB YY 56 78
CC XX 91 23
DD VV 45 67

$[/tmp] > echo "" > test1.txt
$[/tmp] > more test1.txt

$[/tmp] > cat test1.txt test.txt > test2.txt
$[/tmp] > more test2.txt

AA ZZ 12 34
BB YY 56 78
CC XX 91 23
DD VV 45 67

$[/tmp] > cat test.txt | awk '{print $2 " " $3 " " $4}' > test3.txt
$[/tmp] > more test3.txt
ZZ 12 34
YY 56 78
XX 91 23
VV 45 67

$[/tmp] > paste test2.txt test3.txt > test4.txt
$[/tmp] > more test4.txt
ZZ 12 34
AA ZZ 12 34 YY 56 78
BB YY 56 78 XX 91 23
CC XX 91 23 VV 45 67
DD VV 45 67
  #3 (permalink)  
Old 04-17-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
With awk:

Code:
awk ' 
NR==1{printf("%s", $0);next}
{print FS $2,$3,$4;printf("%s", $0)}
END{if(!(NR%2)){print ""}}
' file
Regards
  #4 (permalink)  
Old 04-17-2008
ajp7701 ajp7701 is offline VIP Member  
Supporter
  
 

Join Date: Dec 2007
Posts: 63
thx

the paste command will work! thats perfect. I did not even know about the paste command. thank you!
  #5 (permalink)  
Old 04-17-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Code:
awk 'END{print __}{_=__}{__=$0;$1=_}_' file
Use nawk or /usr/xpg4/bin/awk on Solaris.
  #6 (permalink)  
Old 05-25-2009
jroco jroco is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 13
chek it this!

awk '{ print last,$0; last=$0 }' file.txt

Usefull.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0