Pattern output

Hi All,

Seeking for your assistance on how to get the two pattern below.

Example
file1.txt

GET /Sun/Cellular/version1/12
HTTP/1.0 100 Internal Error
GET /Sun/Cellular/version1
GET /Sun/Cellular/version1
GET /Sun/Cellular/version1
GET /Sun/Cellular/version1/13
HTTP/1.0 100 Internal Error
GET /Sun/Cellular/version1
GET /Sun/Cellular/version1

Expected Output

GET /Sun/Cellular/version1/12
HTTP/1.0 100 Internal Error
GET /Sun/Cellular/version1/13
HTTP/1.0 100 Internal Error

I tried using egrep but it will print all "GET /Sun/Cellular/version1/". what i want is to print records with "HTTP/1.0 100 Internal Error"(please see expected output)

egrep "GET /Sun/Cellular/version1/|HTTP/1.0 100 Internal Error" file1.txt

Thanks in advance.

BR,

---------- Post updated at 03:49 PM ---------- Previous update was at 03:15 PM ----------

Noted Moderator. Sorry.

How about:

grep -e version[0-9]"/" -e Error file1.txt

Hope this helps

Not working sir sea. it's prints all the GET /Sun/Cellular/version1/. what i want is to display the GET /Sun/Cellular/version1/12 and HTTP/1.0 100 Internal Error

Thanks,

You say that what you want is to print records with "HTTP/1.0 100 Internal Error". From the input you supplied that would be:

HTTP/1.0 100 Internal Error
HTTP/1.0 100 Internal Error

but you say that the desired output is:

GET /Sun/Cellular/version1/12
HTTP/1.0 100 Internal Error
GET /Sun/Cellular/version1/13
HTTP/1.0 100 Internal Error

I don't understand what you really want???

Hi Sir Don Cragun,

what i mean is if the record has "HTTP/1.0 100 Internal Error" it will print the GET /Sun/Cellular/version1/* and "HTTP/1.0 100 Internal Error" Please see below sample output

Sample File
GET /Sun/Cellular/version1/12
HTTP/1.0 100 Internal Error
GET /Sun/Cellular/version1
GET /Sun/Cellular/version1
GET /Sun/Cellular/version1
GET /Sun/Cellular/version1/13
HTTP/1.0 100 Internal Error
GET /Sun/Cellular/version1
GET /Sun/Cellular/version1
Expected Output
GET /Sun/Cellular/version1/12
HTTP/1.0 100 Internal Error
GET /Sun/Cellular/version1/13
HTTP/1.0 100 Internal Error

Thanks,

You could check for version1/* and print the next line regardless if error or not..

grep -A1 version1"/"1[23]  file1.txt

Prints:

GET /Sun/Cellular/version1/12
HTTP/1.0 100 Internal Error
--
GET /Sun/Cellular/version1/13
HTTP/1.0 100 Internal Error

grep: No match. T_T

Hello znesotomayor,

Could you please try following and let me know if this helps.

awk '/\/Sun\/Cellular\/version1\/[0-9]*/ {print $0;getline;print $0}' Input_file

Output will be as follows.

GET /Sun/Cellular/version1/12
HTTP/1.0 100 Internal Error
GET /Sun/Cellular/version1/13
HTTP/1.0 100 Internal Error

Thanks,
R. Singh

1 Like

How about - if your grep allows for the -B option -

grep -B1 Error file1
GET /Sun/Cellular/version1/12
HTTP/1.0 100 Internal Error
--
GET /Sun/Cellular/version1/13
HTTP/1.0 100 Internal Error

---------- Post updated at 10:05 ---------- Previous update was at 10:03 ----------

or:

awk '/Error/ {print T; print} {T=$0}' file1
GET /Sun/Cellular/version1/12
HTTP/1.0 100 Internal Error
GET /Sun/Cellular/version1/13
HTTP/1.0 100 Internal Error
1 Like

Wow thank you very much Sir RavinderSingh13 and RudiC it works now.. wew at last... thank you very much all for your support. i think i need to learn more from you guys xD thank u thank u...

BR,

Please be aware that - due to your somewhat unspecific specification - the two proposals are NOT equivalent. RavinderSingh's looks for "...version1/something" and prints two lines from there, no matter if an error exists. Which is fine and fulfills the spec. Mine looks for "Error" and prints this along with the line before it, no matter what the version is.

So - in future specs you should be way clearer about what you really need!