Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk-How to cp $0 that follows a search characer and P before next Sear 1

Status
Not open for further replies.

keusch

Technical User
Jun 17, 2001
41
US
I'm new with Awk -- my files is structured like this:
>,T1N,R1E,S0,M15
108.533020,39.106216
108.533065,39.120697
108.478057,39.106170
108.496017,39.106155
108.514495,39.106155
>,T1N,R1E,S1,M15
108.440109,39.178619
108.421585,39.193130
108.421615,39.179992
108.421615,39.178649
>,T1N,R1E,S2,M15
108.458862,39.178543
108.440109,39.193176
108.440109,39.178619
I want to copy the line directly below >data and paste it above the next >data entry.
I can do it in vi easily, how can it be done in an awk script. I've already built a script to do the other output i need but am having trouble with this. I can't read fast enough to solve my problem.
Thanks!!!!!!
 

Hi, keusch!

If I quite understood your question, I suggest you this awk programm solution:

/>/ {
if (row != "")
print row
print
saveRow = 1
next
}

{
if (saveRow)
row = $0
saveRow = 0
print
}

Please, tell me, does it works.

Bye!

KP.
 
Krunek,
Thanks, your advice got me started and got me thinking. I workded through the logic and added all the other things i needed to print and then ran the statment through grep and through a sed command. it failed on the sed command so - like the novice i am - ran it throurhg two separate scripts to get what was needed. Having plenty of memory makes me slopy but gets the job done. Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top