Search by patterns case


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search by patterns case
# 1  
Old 03-17-2012
Search by patterns case

Code:
 
42   network read failed
sv1 sv23 sv4
sv11 sv23 sv5 sv 7
48  client hostname could not be found
sv21 sv78 sv19 sv22
sv111 sv203 sv5 sv 33
49  client did not start
sv1 sv21
54   timed out connecting to client
sv2 sv4 sv12

above is my file , I'd like to use a script to list all name below the line that starts with "48 client hostname.." untill it finds a line starts with a number in the this case 49. it can be any other number

so the output of would be

Code:
 
sv21 sv78 sv19 sv22
sv111 sv203 sv5 sv 33


Thaanks
# 2  
Old 03-17-2012
awk

Hi,
Try this one,
Code:
awk '/^48/,/^49/'{print $0;} file

Cheers,
Ranga:-)
# 3  
Old 03-17-2012
Quote:
Originally Posted by rangarasan
Hi,
Try this one,
Code:
awk '/^48/,/^49/'{print $0;} file

Cheers,
Ranga:-)

this one wokrks , but the second number can be different thatn 49

i tried this , but it didnt work fine
Code:
 
awk '/^48/,/^[0-9]/'{print $0;} file

# 4  
Old 03-17-2012
awk

What about in sed?
Anyway try this,
Code:
awk '/^48/{t=1;next;}t==1 && $0 !~ /^[0-9]/{print;}/^[0-9]/{t=0;}' file

Cheers,
Ranga:-)
This User Gave Thanks to rangarasan For This Post:
# 5  
Old 03-17-2012
Quote:
Originally Posted by rangarasan
What about in sed?
Anyway try this,
Code:
awk '/^48/{t=1;next;}t==1 && $0 !~ /^[0-9]/{print;}/^[0-9]/{t=0;}' file

Cheers,
Ranga:-)
works perfectly :$
# 6  
Old 03-17-2012
Shortened it a bit:
Code:
awk '/^[0-9]/{p=0}p;/^48/{p=1}' file

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for patterns on different lines

im using the following code to search a log for entries on two different lines: awk 'BEGIN{count=0} /'"${firstpattern}"'/,/'"${secondpattern}"'/ { print; if ($0 ~ /'"${thirdpattern}"'/){count++}; } END { print count }' data.txt firstpattern="start error log" secondpattern="i am logging the... (1 Reply)
Discussion started by: SkySmart
1 Replies

2. Shell Programming and Scripting

Convert text between exact matching patterns to Title case

Hi Folks, I have a large text file with multiple similar patterns on each line like: blank">PATTERN1 some word PATTERN2 title=">PATTERN1 some word PATTERN2 blank">PATTERN1 another word PATTERN2 title=">PATTERN1 another word PATTERN2 blank">PATTERN1 one more time PATTERN2 title=">PATTERN1... (10 Replies)
Discussion started by: martinsmith
10 Replies

3. Shell Programming and Scripting

Search and count patterns

Hi, I have a text file the contents are like this now i want to search patterns Z , Z etc and count the occurrence of such patterns, after Z value can be any random digits, please help me it is urgent... output like this Z .............>5 Z ............>8 (9 Replies)
Discussion started by: sreejithalokkan
9 Replies

4. Shell Programming and Scripting

Search for patterns in thousands of files

Hi All, I want to search for a certain string in thousands of files and these files are distributed over different directories created daily. For that I created a small script in bash but while running it I am getting the below error: /ms.sh: xrealloc: subst.c:5173: cannot allocate... (17 Replies)
Discussion started by: danish0909
17 Replies

5. Shell Programming and Scripting

Question about REGEX Patterns and Case Sensitivity?

Hello All, I'm in the middle of a script and I'm doing some checks with REGEX (i.e. using the '"shopt -s nocasematch" that at least the first one should print "FALSE" but it prints "TRUE"..? For Example: #!/bin/bash MY_VAR="HELLO" ### This prints "TRUE" PATTERN_1="^*" if ] then... (5 Replies)
Discussion started by: mrm5102
5 Replies

6. Shell Programming and Scripting

Search for the two patterns and print everything in between

Hi all, I have a file having data: @HWUSI-EAS1727:19:6:1:3674:984:0:1#GTTAATA NTTGGGTTTTCT @HWUSI-EAS1727:19:6:1:3674:984:0:1#GTTA... NTTGGGTTTTCT @HWUSI-EAS1727:19:6:1:3674:984:0:1#.....CT NTTGGGTTTTCT I want to print everything starting from # till line ends. can you please help me how... (5 Replies)
Discussion started by: pirates.genome
5 Replies

7. Shell Programming and Scripting

search multiple patterns

I have two lists in a file that look like a b b a e f c d f e d c I would like a final list a b c d e f I've tried multiple grep and awk but can't get it to work (8 Replies)
Discussion started by: godzilla07
8 Replies

8. 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

9. Shell Programming and Scripting

sed search alternately for patterns

hi all, I am trying to do search on a gzip file. The file has <pattern1> Data.. <pattern2> data <pattern1> data <patter2> I want to print each pattern 1 and the corrresponding pattern2. If pattern 2 fails to appear and pattern 1 appears, I do not want to print pattern1 and... (3 Replies)
Discussion started by: baskar123
3 Replies

10. Shell Programming and Scripting

search patterns

hello, i have an input file of about 50,00,000 lines. few of its lines are as follows: <CR:0023498789,TPO-14987084;BO=IC&SUB=ALLP <CF:0023498789,CB=YES;BIL&NC=NO <CF:0023498789,CW=NO;NS=NO <GC:0023498789,CG=YES;TPO&NC=YES <CR:0024659841,TPO-14484621;BO=NO&BA=OC&SUB=ALLH... (1 Reply)
Discussion started by: rochitsharma
1 Replies
Login or Register to Ask a Question