swapping lines that match a condition using sed, perl or the like
I'm a bit new to regex and sed/perl stuff, so I would like to ask for some advice. I have tried several variations of scripts I've found on the net, but can't seem to get them to work out just right.
I have a file with the following information...
I have another script that is rearranging this just fine with one exception. The lines that have 'fixed-address' as the last line before the close bracket are working fine. The lines that have 'hardware ethernet' on them are causing my big script to misinterpret the information.
My desired result would be the following...
So what I'd like to build is a script that would search for 'fixed-address'. If it's followed by '}', do nothing. If it's followed by 'hardware ethernet', flip the lines 'fixed-address' and 'hardware ethernet'.
Does anyone have any advice on how they think that they would accomplish this? I'd appreciate any help that someone could provide.
Last edited by TheBigAmbulance; 09-10-2009 at 11:33 AM..
Could any one tell me how to read and match multiple lines in perl? Did this code below still work in this situation?
while (<FILE>) {
if (/ /) {
}
}
Thanks a lot! (5 Replies)
I made a script that can swap info on two lines using a combination of awk and sed, but was hoping to consolidate the script to make it run faster. If found this script, but can't seem to get it to work in a bash shell. I keep getting the error "Too many {'s". Any help here would be appreciated:... (38 Replies)
First of all, I know this can be more eassily done with perl or other scripting languages but, that's not the issue. I need this in sed. (or wander if it's possible )
I got a file (trace file to recreate the control file from oracle for the dba boys)
which contains
some lines
another line... (11 Replies)
Hi folks,
I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and... (5 Replies)
Greetings all,
I am trying to match a string, and after that insert a few lines above that match.
The string is "Version 1.0.0". I need to insert a few lines ONLY above the first match (there are many Version numbers in the file). The rest of the matches must be ignored. The lines I need to... (2 Replies)
Hello,
Could someone help me with sed. I have searched for solution 5 days allready :wall:, but cant find. Unfortunately my "sed" knowledge not good enough to manage it. I have the text:
123, foo1, bar1, short text1, dat1e, stable_pattern
124, foo2, bar2, long text
with few
lines, date,... (4 Replies)
I want to do something like sed -n '/PATTERN/,+10p' and get the ten lines following PATTERN. However, this throws an "expected context address" with the sed that comes with OSX Lion. If that + is a GNUism, can I do this, or do I have to find another tool? (2 Replies)