|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
I am using an egrep to output all successful entries of a batch script I am running. The batch file runs, and if successful, it codes an entry in the file that begins with the identifier for that batch.
Ex: Batch for location id 20 = if batch is successful, I get 20xxxxxxxxxxxxxxx.out = file. This part is hard-coded from an application, I can't change the filename. What I am doing is using egrep to search the contents of all these files, looking for the successful batches... the output is: Successful Batches $date ------------------------- /path/20xxxxxxxxxxxx.out /path/21xxxxxxxxxxxx.out /path/22xxxxxxxxxxxx.out /path/23xxxxxxxxxxxx.out I already have: sed 's/\/path\//Location /g' to get rid of the path, but now I need to get rid of the xxxxxxxxxxxxxx.out portion, which always begins with the 9th character of the line (I can't truncate all lines due to the headers, etc.) End all goal is Successful Batches $date ------------------------- Location 20 Location 21 Location 22 Location 23 All help appreciated, apologize if the explanation is confusing. |
|
#2
|
|||
|
|||
|
yes, confusing
assumed, you are looking for digits after '/path/' try sed -ne 's/\/path\/\([0-9]*[0-9]\).*/location \1/p' post the batch, i am sure you do not NEED grep |
|
#3
|
|||
|
|||
|
Quote:
Apologize for the confusion... perhaps let's forget all about the egrep, and look at only the output I'm trying to get. Your statement does do me some good (although I'm having trouble interpreting it step by step). It does replace the path, which I have been able to do thus far - and in addition, it removes the .out file extension from the list. The only thing left I need to get rid of is the xxxxxxxxxx string that is the filename after the first 2 characters which identify the location. Thus, my output would be "Location 20" where 20 WAS the first two characters of the filename. I'm sure there is an easier way to go about this, but my lack of experience and the sensitivity of the data in the batch file prevent me from disclosing much more. Appreciate your help! |
|
#4
|
|||
|
|||
|
EDITfor Stupidity, leaving so someone else can learn at my expense: Remove the -ne!
Follow-up... A slight modification to your line, and it is giving me the output I want: sed -ne 's/\/credit_auth\/\([0-9][0-9]\).*/Location \1/p' Output is: Location 20 without the remaining filename or the .out extension. Now all I need to do is make it only process on lines which actually HAVE that path, because right now it is deleting my header. Many thanks! |
|
#5
|
|||
|
|||
|
bkpatterson
grep is a wonderfull tool sed is (a lot of times) better a little read of manuals && experience && you see it |
|
#6
|
|||
|
|||
|
guggach - Thanks again for your assistance, it has been most helpful. I have obtained an older copy of a book: "Unix Text Processing" - I am well on my way.
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > SED Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|