Extract values only for certain tags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract values only for certain tags
# 8  
Old 12-10-2014
Hello fretagi,

You can use following also.

Code:
awk -F":" '($1 == "MSISDN" || $1 == "IMSI") {print}'  Input_file

Output will be as follows.
Code:
MSISDN: 258827475309
IMSI: 643012111658984
IMSI: 643012112814555
IMSI: 643012111658984
MSISDN: 258827475309

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 9  
Old 12-10-2014
thank you Ravinder, neat output
# 10  
Old 12-10-2014
Hello fretagi,

Above code will look for keywords in first column, if you need to look for given keywords in whole line, please use following for same.

Code:
awk '($0 ~ /MSISDN/ || $0 ~ /IMSI/) {print}'  Input_file

Output will be as follows.
Code:
MSISDN: 258827475309
IMSI: 643012111658984
dn: IMSI=643012112814555,dc=imsi,ou=identities,dc=mcel
objectClass: IMSI
IMSI: 643012112814555
IMSI: 643012111658984
MSISDN: 258827475309

Thanks,
R. Singh
# 11  
Old 12-10-2014
your first option is better, because I just want the numbers..., but please can you explain me the syntax?
# 12  
Old 12-10-2014
Quote:
Originally Posted by fretagi
your first option is better, because I just want the numbers..., but please can you explain me the syntax?
Hello fretagi,

Here is the explaination for same.

Code:
awk -F":" '($1 == "MSISDN" || $1 == "IMSI") {print}'  Input_file

I have taken delimiter as : and then I am checking the first column of it if 1st column is either keyword MSISDN or IMSI then print the lines else do nothing.

Hope this helps, let me know if you have more doubts on same.

Thanks,
R. Singh

Last edited by RavinderSingh13; 12-10-2014 at 06:22 AM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 13  
Old 12-10-2014
Thank you
# 14  
Old 12-10-2014
Quote:
Originally Posted by fretagi
... because I just want the numbers ...
It should work if you use {print $2} instead of {print} (print only field 2 instead of whole line), but there will be a leading space.
If you don't want the preceding space, try this:
{sub(/^ /,"",$2); print $2} it means remove a single preceding space from the field 2 + print field 2. In fact it means substitute the preceding space with nothing ("").
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract multiple values into corresponding variables

Here is my input # MANIFEST.MF Manifest-Version: 1.0 Build-Jdk: 1.6.0 Built-By: CM_TEAM Build_SvnRev: 662789 Build_Number: 13.0.0.0-JDK8 Build_Date: Wed 04/05/2017-20:48:19.17 Archiver-Version: Plexus Archiver Created-By: Apache Maven 3.1.0 Here is the expected output:... (4 Replies)
Discussion started by: kchinnam
4 Replies

2. Shell Programming and Scripting

Extract values in a line using awk

hello all, I need your help in extracting values of some parameter within a line using awk. for example: i have the below line available in a file and i want to extract the values of only CustomerId, s_PackageId and s_HZINumbers in order the result to be as ... (13 Replies)
Discussion started by: nael_najib
13 Replies

3. Shell Programming and Scripting

Extract values

hi I have a line as given below. I need to match "COLUMN_NAME" and get the every third value ie words in between quotes completely (' ') Sample Input - COLUMN_NAME Like '%value%' Or COLUMN_NAME Like '%value%' Or COLUMN_NAME Like '%value value%' Or COLUMN_NAME Like '%value%' OR... (5 Replies)
Discussion started by: Prashanth B
5 Replies

4. Shell Programming and Scripting

Is it possible to extract these values from the output

Hi, I would like to search based of "java" and "-Dplatform.home=" and store these two values in bash variables. ps -xef | grep <pid> wlsuser 15160 15144 0 Feb 20 ? 17:27 /app1/jdk150_07/bin/IA64N/java -server -Xms1536m -Dplatform.home=/app1/bea/weblogic92... (13 Replies)
Discussion started by: mohtashims
13 Replies

5. Shell Programming and Scripting

extract key values

I am parsing a log with key values spread all over in the following fashion: TEST 1 SCHEME 12 SET EMPTY VARLEN SET TEST 1201 PARAM1 EMTY PARAM2 SET SCHEME 12 REFRESH TEST 8 I need to extract test number, my result should be 1 1201 8 I use awk for processing this log and use... (4 Replies)
Discussion started by: migurus
4 Replies

6. Shell Programming and Scripting

to extract specific values twice in a file

Hi Friends, I have a file with the following values.. xyz.txt,12345.xml abc.txt,04567.xml cde.txt,12134.xml I would like to extract all the 2nd column values twice as shown in the example like 12345,12345.xml 04567,04567.xml 12134,12134.xml Please advice!! In the formus one of... (7 Replies)
Discussion started by: techmoris
7 Replies

7. Shell Programming and Scripting

Extract Values from CSV

Hi, I need to extract values from a CSV file based on some conditions as explained below: File format details: 1. each set starts with AAA only 2. number of columns is fixed 3. number of rows per set may vary (as they are having different CCC rows) Now, i need to extract 3rd column of... (3 Replies)
Discussion started by: prvnrk
3 Replies

8. Shell Programming and Scripting

Extract XML Element Values

I have a rather large file with XML-style content. Each line contains one full XML entry. For example: 1:<Message><DNIS>1234</DNIS><UCID>3456</UCID><TransferGroup>XYZXYZ</TransferGroup></Message> 2:<Message><DNIS>9999</DNIS><UCID>2584</UCID><TransferGroup>ABCABC</TransferGroup></Message>... (1 Reply)
Discussion started by: sharpi03
1 Replies

9. Shell Programming and Scripting

how to extract values b/w two delimiters

Hi, Please help me to extrat values b/w two delimiters. $ echo $abc i want to extract the value 12345 b/w %. (5 Replies)
Discussion started by: tsaravanan
5 Replies

10. Shell Programming and Scripting

Extract values from log file

I would like to write a shell script that will parse through a file similar to the sample below. The data in the file is redirected from rsync into a log file. I would like to call a shell script to parse through and pick out the number beside the percent sign inside the parentheses in the last... (5 Replies)
Discussion started by: wdympcf
5 Replies
Login or Register to Ask a Question