|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Displaying text till pattern match found in a line
Hi All, From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able to print text before the pattern. it display texts which is found after pattern. Code:
awk '/[Pp]assed/{print;getline;print}' file_name | sed 's/^[^:]*. *//'input line from the file_name looks like Code:
U12-C02: Software checks is passed. (Latest Software version : IED-2011-S : upgrade_01 4.13.2 (4.10.15_TREP-RT_13.31)) Currently it is displaying like this : Code:
Software checks is passed. (Latest Software version : IED-2011-S : upgrade_01 4.13.2 (4.10.15_TREP-RT_13.31)) expected output should be like this : Code:
U12-C02: Software checks is passed. Many Thanks, Optimus |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Code:
awk '{for(i=1;i<=NF;i++){if($i ~ /[pP]assed/){s=s?s" "$i:$i; print s;s="";next}else{s=s?s" "$i:$i;}}}' file |
|
#4
|
|||
|
|||
|
Code:
awk -F '.' '/[Pp]assed/{print $1 ;getline;print $1}' file_nameIf you display several line of text from you input file, maybe we can do better than just guess as to what we we're reading. I do not see why you have getline in there. Your expected output is just a single line, per your example. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks Franklin. It works fine.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To add a new line with specific text after the pattern is found using sed | smarlaku | Shell Programming and Scripting | 1 | 01-11-2013 02:27 AM |
| Pattern match till the end of the file. | halfafringe | Shell Programming and Scripting | 2 | 07-06-2012 04:47 AM |
| Grep the word from pattern line and update in subsequent lines till next pattern line reached | rbalaj16 | Shell Programming and Scripting | 5 | 06-18-2012 04:39 AM |
| Print characters till the next space when the pattern is found | gpk_newbie | Shell Programming and Scripting | 2 | 10-19-2011 05:02 AM |
| Awk script to match pattern till blank line | justchill | Shell Programming and Scripting | 7 | 11-19-2010 03:33 AM |
|
|