sed match
Hi, I have a new problem with sed matching:
Code:
sed -n '/Content-Disposition/{ /".*"/!N} Code:
... Code:
Content-Disposition: attachment; filename= Ted |
Well not having great sed juju, I would guess at the issue being you have not setup looping to cover more than 2 lines.
I would look at this and implement it to replace the first 2 lines of your script with one that loops until it finds what you need. Let me know if you get stuck? |
Hi,
grail is right. Your sed is not able to match over multiple lines. In addition, You will get some whitespace issues in the filename when you simply erase the '\n'. You will also have to erase the trailing blanks in the lines. This worked with your sample data: Code:
sed -rn '/Content-Disposition/ {:a /filename=".*"/! {N;s/\n[[:blank:]]*//g;ba};s/.*"(.*)"/\1/;p}' file |
Slight correction for crts' typo, the -r switch is the one to notice ;)
I do have a slight OT question for crts though - are you able to explain the difference between using ba as opposed to ta? They both seem to branch but when do you use which? |
Quote:
Quote:
The 'T' command works similiar but it branches only when no substitutions were made by a preceding 's///'. This sed works similiar: Code:
sed -rn '/Content-Disposition/ {:a /filename=".*"/! N;s/\n[[:blank:]]*//g;ta;s/.*"(.*)"/\1/;p}' file One more thing to know, is that the condition 's/// has made a substitution' is being reset when a 't' command jumps. |
Hi Sirs,
I have a similar issue, instead of replace the string with multiple lines, I need to replace a keyword in an xml file with the contents of a txt file containing multiple lines. the xml file has a keyowrd 'kw01', and i want to replace this string with the contents of a file named fatal_alerts.txt. is this possible via sed? i badly need this. TIA! keyword to be replaced: kw01 fatal_alerts.txt contents: RAISEDATTIME -------------------- DESCRIPTION ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 18-APR-2011 06:20:32 Fatal error in Application GATE: <Error code: 68 Caught by: CTCS_BatchSchedulerBO.HandleException Raise by: CTCS_FTOServerBTM.ValidateMessageCount() Message: For Interface: FTO:1315001 in File : 190107079531.txt File Message Count Mismatch. File reported count: 447 actual message count 797.> |
thanks crts ... complete answer as always :)
|
Quote:
|
All times are GMT -5. The time now is 07:28 PM. |