fixengineer
Technical User
I want to display a log file in a more readable format.
The core thing is to look for one string in a line then when found take certain data from that line and insert it above the line. If you found a line with CarType=Race, find out what the tire size is in that line and then copy and insert it above the line. I'm playing around with sed 'i' and 'h' and 'g' and also the markers \(\). No go so far.
Basically I need to say with sed or awk: "look for 'CarType=Race' in file 'cars.dat' and display each line after you check it. When you find 'CarType=Race', search within that line for 'TireSize=AndTheNext3CharactersAfterString'.(In this case '12"'). Hold 'TireSize=AndTheNext3CharactersAfterString' and wildcard characters(...) and insert a space and then 'TireSize=AndTheNext3CharactersAfterString' above line where you found 'CarType=Race'.
The format I want is as such:
-----------------------------
Tire size=12"
CarType=Race TireSize=12" Color=Blue
CarType=Sedan TireSize=14" Color=Black
The file is in this format:
----------------------------
CarType=Race TireSize=12" Color=Blue
CarType=Sedan TireSize=14" Color=Black
Thank you very much for your help on this. Trying to build a tool that will make my work so much easier and efficient. Yes...I'm at it again!
The core thing is to look for one string in a line then when found take certain data from that line and insert it above the line. If you found a line with CarType=Race, find out what the tire size is in that line and then copy and insert it above the line. I'm playing around with sed 'i' and 'h' and 'g' and also the markers \(\). No go so far.
Basically I need to say with sed or awk: "look for 'CarType=Race' in file 'cars.dat' and display each line after you check it. When you find 'CarType=Race', search within that line for 'TireSize=AndTheNext3CharactersAfterString'.(In this case '12"'). Hold 'TireSize=AndTheNext3CharactersAfterString' and wildcard characters(...) and insert a space and then 'TireSize=AndTheNext3CharactersAfterString' above line where you found 'CarType=Race'.
The format I want is as such:
-----------------------------
Tire size=12"
CarType=Race TireSize=12" Color=Blue
CarType=Sedan TireSize=14" Color=Black
The file is in this format:
----------------------------
CarType=Race TireSize=12" Color=Blue
CarType=Sedan TireSize=14" Color=Black
Thank you very much for your help on this. Trying to build a tool that will make my work so much easier and efficient. Yes...I'm at it again!