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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a line and moving the contents of the line below one step up 1

Status
Not open for further replies.

hill007

Technical User
Mar 9, 2004
60
US
Hi,

I have a large file where I need to remove some repetitive statements and then move the contents below the removed line to the position of that line. To be clear here is an example.

Current file:

1 2 3 A B
5 6 1 2 3
CONTENTS 1 0 2
1 2 3 4 5
1 3 T B 6
CONTENTS 1 0 2
P Q W 4 7
CONTENTS 1 0 2

The final outcome of the file should look like:
1 2 3 A B
5 6 1 2 3
1 2 3 4 5
1 3 T B 6
P Q W 4 7

Any help appreciated.

Thanks.


 
Something like this ?
awk '!/^CONTENTS/' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,
I could'nt understand the /path/to/input in the code.
Could you please explain the code.
Thanks.
 
replace /path/to/input by your pathname of the file you want to play with.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Can you please post the input file, the exact code you tried and the result you obtained versus the expected result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

I have written my input file as TEST.DAT
Here is the input file:

1 2 3 A B
5 6 1 2 3
0 0 CONTENTS 1 0 2
1 2 3 4 5
1 3 T B 6
0 0 CONTENTS 1 0 2
P Q W 4 7
0 0 CONTENTS 1 0 2

I have written your code in a TEST.AWK file:
{ !/^CONTENTS/ }

I then ran awk95 from the directory which had the awk95.exe as well as the test.dat and test.awk files.

I used the command:

awk95-f test.awk test.dat > test1.dat

When I run the command it gives test1.dat with empty file.
 
awk95 '!/CONTENTS/' test.dat > test1.dat
Some notes:
1) your test.dat file isn't the same as in your original post
2) your test.awk file isn't what I suggested you (no curly brace in my post)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

Sorry. It was my fault. The code works perfectly.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top