This is a perfect example to explain how to tackle such seemingly complex problems. In fact it is simple and straightforward:
Quote:
Originally Posted by John Trevor
but I'm not sure how to do this prefixing in sed. Can you give me a sample code snippet to start with ?
First, we single out all lines with "TicketNumber===>" i them. These are the only lines we need to work on in this step:
This does nothing more than to print the lines we want to work on: first check, if we found all the lines we want to find and didn'tfind all the lines we do not want to find. If the result is OK, we proceed.
Second, we catch the "word" immediately following the string "TicketNumber===>", because this is the ticket number itself. We display this ticket number instead of the original line to make sure we got that right:
Check again and compare with your input to make sure this is what you want - in case it isn't you will adapt the regexp until finally getting what you want.
Then proceed to the final step: we prepend every line with a ticket number in it with a field with the ticket number we have just isolated:
Some obeservations: First, as you are only interested in the first and the last line of every transaction - that is, for every ticket number the opening and the closing line - you could throw away all lines in between, yes? If you search for both of these lines and prepend both with the ticket number a simple "sort" will provide the ordering so you can process the resulting file line by line:
Second: you probably will not need some of the information in the source lines. By adapting the replacement part(s) of the regexps you can further trim down the resultfile to contain only the information you need.
You will probably have to fine-tune this to completely meet your needs, but this should give you a good start.
Hi,
I need to remove lines from a text file that are less than certain length in UNIX. For example, test.txt file contains the following lines:
abcdefghijklmnopqrstuvwxyz.
123456789009876543211234567
This line to be removed.
zyxwvutsrqponmlkjihgfedcba.
The length of each line is supposed... (5 Replies)
I am a new unix user & I wanted to work with unix as it is very good in text manipulations. I need a little help. I will be grateful if someone can help me out.
I need help in grepping a pattern of numbers from one file to another file. Specific details are as follows:
File one contains only... (4 Replies)
I have a text file having number of different rows like this..
Action & Adventure|Whiteout|
Kids Free|PBS KIDS Sprout|En espanol|
Kids Free|PBS KIDS Sprout|En espanol|XYZ|
Basically,i want to read the file and write to another file in a tree structure like this..
each row should have 6... (7 Replies)
What I am trying to do is make a script that will add a port number within a section of a file if it already doesn't exist in that section of the file. The particular line that I would like to add the port number to in the file is formatted like this:
TCPPORTS="25 80 125 443 8080 10000"
For... (3 Replies)
Hi,
I need to write shell script for the scenario explained below -
datafile.txt
AcctNum,code,Region,,,,
12345451,AN ,abaab
12345452,AN ,xccxc
76677545,RP ,acxcc
43567878,RP ,afghh
32190900,AN ,afrfrf
87312345,AN ,aqaw
I have a text file (datafile.txt)... (1 Reply)
Hi ,
I have a simple text file with contents as below:
12345678900 971,76 4234560890
22345678900 5971,72 5234560990
32345678900 71,12 6234560190
the new csv-file should be like:
Column1;Column2;Column3;Column4;Column5
123456;78900;971,76;423456;0890... (9 Replies)
I have a tab delimited file with 4 columns. If the value in the first column, equals the value in the second column, I'd like to have the 4th column multiplied by 2 then add 1. If the value in the first column differs from the value in the second, I'd like to have the 4th column multiplied by 2... (5 Replies)
Hi Gurus,
I have a question
I have a flat file like below with three fields (3 rd field is amt)
ad|B|500
cc||100
dd|C|600
ee||900
Need to write a code in such a way that when second field is empty then do sum of third field
So in this case it will be 100 +900
I tried but no luck... (1 Reply)
Hello,
Supposing I had a huge list as follows:
TAC manufacturer Device Type
1392600 LG D959 LG-D959TS FeaturePhone
1409700 LG V410 FeaturePhone
35150806 LG F350S FeaturePhone
35165206 Samsung GT-E1200 FeaturePhone
35194505 Nokia Asha 200 FeaturePhone
but I want to make it look like... (3 Replies)