Scrutinizer's code makes assumptions about what the 1st line of a header looks like (based on your sample input) that might not be true in your real data and only requires that the 3rd line of a header contain From= somewhere on the line. It will also delete a 3 line header if the next 3 line header is the same as the previous 3 line header even if those headers are not adjacent.
The following code makes no assumptions about what the 1st two lines of a 3 line header look like, assumes that the 3rd line must start with From= and must also contain , To=. It will only remove a 3 line header if the next three lines match that header. I asked questions about the header format (all three lines) and got no response, so I still have no idea if the following code will do what is desired. I believe it meets all stated requirements:
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.
With the following input:
this script produces the output:
while Scrutinizer's script produces:
If you're unwilling to show us the output you're getting from these scripts with your sample input, there isn't much we can do to help.
These 2 Users Gave Thanks to Don Cragun For This Post:
Scrutinizer's code makes assumptions about what the 1st line of a header looks like (based on your sample input) that might not be true in your real data and only requires that the 3rd line of a header contain From= somewhere on the line. It will also delete a 3 line header if the next 3 line header is the same as the previous 3 line header even if those headers are not adjacent.
[..]
Good catch about the adjacency, Don. Quick fix:
But further robustness would need to be added and "From=" would need to be always present...
Hi
I have a file with contents:
NAMES
John
carrey
williams
How can I get all the names and store them in seperate variables(or arrays)
please keep in mind that the no. of such names is not known.Three here is a bogus value
~thanks (4 Replies)
Ok hope my vocab is right here, i'm trying to write multiple sets of arguments to another file for example:
I have a script that accepts four arguments and sends them to a another file
$write.sh it then out in
so the file receiver.txt would contain this:
it then out in
what... (2 Replies)
I have a diff command that does what I want but when comparing large text/log files, it uses up all the memory I have (sometimes over 8gig of memory)
diff file1.txt file2.txt | grep '^<'| awk '{$1="";print $0}' | sed 's/^ *//'
Is there a better more efficient way to find the lines in one file... (5 Replies)
Hi everyone,
I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines).
Does anybody have an idea how to do that using perl, awk or sed?... (6 Replies)
I have one base file, and multiple target files-- each have uniform line structure so no need to use grep to find things-- can just define sections by line number.
My question is quite simple-- can I use sed to copy a defined block of lines (say lines 5-10) from filename1.txt to overwrite an... (3 Replies)
Hello, i am new to the forum and know nothing about programing, Linux or Unix :( hope somebody can help me out.
I have a .txt file that i need to delete certain lines from. After searching the forum i noticed that using "sed" was the way to go, so i installed gnuwin32 (i use windows xp... (4 Replies)
I need some help deleting lines in a file that contain spaces. Im sure awk or sed will work but i dont know much about those commands. Any help is appreciated :D (7 Replies)
In other news, I have a colors text file with hundreds of lines, and I want to print only the even numbered lines. for example I have this file looks something like this:
ALLCOLORS.TXT
red red green red
blue red red red
green red red blue
green green green
blue blue blue
red blue blue blue... (1 Reply)