Ignoring newlines in my search


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ignoring newlines in my search
# 1  
Old 04-08-2010
Ignoring newlines in my search

I have a file that has lines that are deliminated with '^A', but some of the lines go for a few lines and I need those lines to be appended into one line.

All of the lines start with 'low debug' and end with ' " 0 '.

How can I read each line from start to finish without some of the data being screwed up because the middle of the line starts at a new line.

Here are some examples:
This is an example of a line that is correct from beginning to end:
Code:
low debug 2010/4/1 9:00:33.40 ICSNotificationAlarm Prodics01ics0001 ICS "1.0^AB^A7611^A1270130433400^A1965^A1963^A2^Am[0]=801^A10635^AProdfixcas11v2fix61^ACD
890/CM/ConsumerProxy@29002971^Am[1]=19002^A10635^AProdfixcas11v2fix61^ACD890/CM/ConsumerProxy@29002971^A" 0

Notice how the line is deliminated with ^A. I use those fields in the data that I need to capture.

Here is an example of one that is broken up into a few new lines which does not help because when I try to search for $7(the 7th value), my data gets all screwed up because that value is on a new line and since the value number starts over each time a new line begins, everything gets messed up.

Code:
low debug 2010/4/1 9:00:37.38 ICSNotificationAlarm Prodics01ics0001 ICS "1.0^AB^A7612^A1270130437380^A31829^A31827^A1^Am[0]=31806^A[[(ProdBC10x1OHServerHybri
dprdbc10b) ]] OhsSender(W_MAIN.ProdBC10x1HybridTradeServer4.Sender): : Exception while sending data to OHS.
-------- Exception --------
org.omg.CORBA.TIMEOUT: Request timed out after 10000065563 ns, falseNotifies(0). RequestId(2), typeId(IDL:orderHandlingServices/ManualOrderMaintenanceService
:1.0), operation(getQuoteQueryDataForProducts), orbName(ProdBC10x1OHServerHybridprdbc10b), iiopHost(prdbc10b), iiopPort(18202), tiopHost(prdbc10b), tiopPort(
18701)  vmcid: 0x0  minor code: 0 completed: Maybe
-------- Trace ------------
com.cboe.ORBInfra.Transport.PendingRequestManager.waitForCompletion(PendingRequestManager.java:133)
com.cboe.IIOPTransport.IIOPClientConnection.receiveReply(IIOPClientConnection.java:529)
com.cboe.IIOPTransport.IIOPClientConnection.receiveReply(IIOPClientConnection.java:513)
com.cboe.IIOPTransport.IIOPClientConnection.receiveReply(IIOPClientConnection.java:507)
com.cboe.ORBInfra.ORB.GenericBindMediator.twoWaySendAndReceive(GenericBindMediator.java:259)
com.cboe.ORBInfra.ORB.DelegateImpl.invoke(DelegateImpl.java:693)
org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:457)
com.cboe.idl.orderHandlingServices._ManualOrderMaintenanceServiceStub.getQuoteQueryDataForProducts(_ManualOrderMaintenanceServiceStub.java:519)
com.cboe.ohsadapters.par.orderHandling.ParManualOrderMaintenanceServiceProxyImpl.getQuoteQueryDataForProducts(ParManualOrderMaintenanceServiceProxyImpl.java:
325)
com.cboe.ohsadapters.par.orderHandling.formatters.outbound.TopOfTheSpreadBookRequestHandler.sendMessage(TopOfTheSpreadBookRequestHandler.java:52)
com.cboe.ohsadapters.par.orderHandling.formatters.OhsOutboundHandler.send(OhsOutboundHandler.java:96)
com.cboe.ohsadapters.par.orderHandling.OhsSender.doTask(OhsSender.java:120)
com.cboe.lwt.thread.ThreadTask.execute(ThreadTask.java:365)
com.cboe.lwt.thread.WorkerThread.run(WorkerThread.java:164)
java.lang.Thread.run(Thread.java:619)
^AProdOHSA00ParAdapter9pprdaps04aA^AParAdapter^A" 0

Notice here, the beginning of the first line starts with 'low debug', and the end of the last line ends with ' " 0 ' but every com.cboe is a new line along with a few others, like -------- Exception -------- and -------- Trace ------------ are new lines. I need this too all be one line.

Please help. Thanks!!!

Last edited by ndedhia1; 04-08-2010 at 12:44 PM.. Reason: edited code tags
# 2  
Old 04-08-2010
Something like this:
Code:
  
awk '/low/ && $0 ~ /0 $/ {print ; next } /low/ { a=$0;next } $0 ~ /0 $/ {a=a""$0;print a ;a=""} {a=a""$0;next}' input_file


Last edited by panyam; 04-08-2010 at 01:17 PM..
# 3  
Old 04-08-2010
I tried that put I did not get any result.
Can you please explain to me what the code is doing?
Maybe I can explain it better also:
I have a file in which contains lines or error messages.
Those messages are deliminated with '^A' and each line has exactly the same number of values.
In my code, I take value number 1 and do something with it, value number 2 and do something with, etc, till I hit the last value.
95% of the file contains individual lines that all start with the 'low' and end with ' " 0' so those lines, I am having no trouble with.
5% of the file contains these lines over multiple lines and here is where I am running into a problem. If I try to do something with value 4, but it is on the 2nd line, then my grep gets all screwed up because i am not grepping over multiple lines.
So i need either one of two things.
Either I need to know how to grep over multiple lines so that newlines arent a problem or I need to figure out how to append all the lines that dont start with either 'low' or dont end with ' " 0"

Thanks!!
# 4  
Old 04-08-2010
The code , i suggested will concatanate the line having "low" in the start and all the lines till it find's "0" in the end of the line to a single line. If the line have "low" and "0" in the start and end respectively in a single line, it will just print those.

Last edited by panyam; 04-08-2010 at 01:09 PM..
# 5  
Old 04-08-2010
i just realized that the line ends with a space after the 0 at the end.
Is there a way to do it so that we can have each line start with "low" but end with '" 0 ' (thats a quote space zero space)

Thanks a lot!!!
# 6  
Old 04-08-2010
Quote:
Originally Posted by ndedhia1
i just realized that the line ends with a space after the 0 at the end.
Is there a way to do it so that we can have each line start with "low" but end with '" 0 ' (thats a quote space zero space)

Thanks a lot!!!
I just modified my previous script , have a look at it.
# 7  
Old 04-08-2010
I really want to thank you!!
This worked out for me...
if you have a second, can you break down the code a bit to explain what you did. I am just trying to learn as much as i can.

Thanks a lot!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX file with Newlines

Hi Friends, I have a data file with new lines. How to remove the newlines and should be showed in one line. I tried using the command tr -d '\n' filename sed 's/\n//g' file name Ex: 1 abc hyd is actual record but in our scenario showing it as 1 abc hydthis record should be like... (5 Replies)
Discussion started by: victory
5 Replies

2. Shell Programming and Scripting

File formatting with newlines

Hi All - I am in need of some help in formating the below file Requirement - 1) replace newlines with space 2) replace '#~# ' with newline ----------------------- sample inputfile a I|abc|abc|aaa#~# I|sddddd|tya|dfg sfd ssss#~# I|tya1|tya2|dfg|sfd|aaa#~#... (5 Replies)
Discussion started by: J1nx007
5 Replies

3. Shell Programming and Scripting

awk search for max and min while ignoring special character

I am trying to get a simple min/max script to work with the below input. Note the special character (">") within it. Script awk 'BEGIN{max=0}{if(($1)>max) max=($1)}END {print max}' awk 'BEGIN{min=0}{if(($2)<min) min=($2)}END {print min}' Input -122.2840 42.0009 -119.9950 ... (7 Replies)
Discussion started by: ncwxpanther
7 Replies

4. UNIX for Dummies Questions & Answers

Remove newlines

Hi buddy's my file are like this: s.no,name,band,sal 1,"suneel",,10 2,"bargav sand",,20 30," ebdug gil",,4 but i want s.no,name,band,sal 1,"suneel",,10 2,"bargav sand",,20 30,"ebdug gil",,4 any command or Shell script for this. please help me it's urgent to implement (33 Replies)
Discussion started by: Suneelbabu.etl
33 Replies

5. Shell Programming and Scripting

Replace commas with newlines

Good afternoon, I am trying to read user input. Here is what I have so far: echo "Type the Container ID for every container that you want subnets exported" echo "for (with comma between each one, for example... 1,45,98)" echo -n "if you want every one listed, then just type ALL in caps... (2 Replies)
Discussion started by: brianjb
2 Replies

6. Shell Programming and Scripting

Delete newlines after every one space

Hi All, I have a file which looks like this: abc 3456 computer 3214 printer 0.9823 computer 3214 Can anyone please let me know how I can format my text like this? abc 3456 computer 3214 printer 0.9823 computer 3214 I know how to space to newlines using tr but don't know how to do... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

7. Shell Programming and Scripting

sed ignoring case for search but respecting case for subtitute

Hi I want to make string substitution ignoring case for search but respecting case for subtitute. Ex changing all occurences of "original" in a file to "substitute": original becomes substitute Origninal becomes Substitute ORIGINAL becomes SUBSTITUTE I know this a little special but it's not... (1 Reply)
Discussion started by: kmchen
1 Replies

8. Shell Programming and Scripting

Ignoring case in sed search

I am getting a parameter from a user and I need to use it to search and return the matching line numbers in a file. I am using this code: recordNumber="$(sed -n '/'"$entry"'/{ = d }' unixdb1.txt)" where $entry is the passed search parameter. The problem is I need to ignore the case. ... (3 Replies)
Discussion started by: snag49ers
3 Replies

9. Shell Programming and Scripting

Remove improperly placed newlines

Hello, there. I have a file that's a horrible, horrible mess. (Basically, it's an export from a firewall config.) The people who generated the file didn't think that putting a newline in the middle of a hostname would ever be a problem. It is. Here's an example of the stuff in the file: ... (2 Replies)
Discussion started by: mikesimone
2 Replies

10. Shell Programming and Scripting

Transpose with two newlines as delimiter

Hi Guys, I have data in a file as follows: a 1 2 3 b 4 5 6 a 6 7 8 a 4 7 9 b 6 8 5 c 0 8 7 So the number of rows which have data is variable (2 for the first group, one for the second group and three for the third group), but the delimiters between the... (10 Replies)
Discussion started by: npatwardhan
10 Replies
Login or Register to Ask a Question