How to get the values of multipledot(.) separated fields?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get the values of multipledot(.) separated fields?
# 1  
Old 04-23-2015
How to get the values of multipledot(.) separated fields?

Hello,

I have a file which has the following contents :

Code:
thewall............0000000000200000  kmemfreelater......0000000000000000
kmemgcintvl........0000000000000002  kmeminuse..........00000000223411C0
allocated..........0000000029394000  bucket.......... @.F1000A02800C2158

The mentioned values are the hexadecimal values. I need to get the values of thewall and allocated respectively. The problem here is that there can be n number of dots(.) and I am unable to retrieve the respective hexadecimal values because number of dots might vary from server to server.

Please help. Thanks a lot Smilie

Rahul

Last edited by vgersh99; 04-23-2015 at 09:37 AM.. Reason: code tags, please!
# 2  
Old 04-23-2015
Try something like:
Code:
sed -n 's/.*thewall[.][.]*\([^[:blank:]]*\).*/\1/p' file

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 04-23-2015
Hello Can you please explain how the above command works. It worked fine for me Smilie
# 4  
Old 04-23-2015
1. sed -n (don't print unless we say so)
2. s/.*thewall[.][.]* (match anything followed by "thewall" followed by one dot followed by zero or more dots)
3. \([^[:blank:]]*\) (match and capture anything that is not a blank/return)
4. .* (match anything else)
5. /\1/ (replace with captured match)
6. p (print it)

You'd can use the -e option to sed to do multiple things, so you can repeat the construct for "allocated". There could be a problem if there are strings like "anotherthewall" or "somethingelseallocated".
This User Gave Thanks to cjcox For This Post:
# 5  
Old 04-23-2015
If it finds a line with "the wall" followed by at least one dot, then it replaces everything on the line, except the part after the dots, this is signified by
Code:
\([^[:blank:]]*\)

which means zero or more characters that are not a space. De escaped parentheses signify a nested subexpression, which is referenced in the replacement part by \1.
The -n option means do not print, while the p-flag at the end means "print if the substitution was successful"
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. UNIX for Beginners Questions & Answers

How to extract fields from a CSV i.e comma separated where some of the fields having comma as value?

can anyone help me!!!! How to I parse the CSV file file name : abc.csv (csv file) The above file containing data like abv,sfs,,hju,',',jkk wff,fst,,rgr,',',rgr ere,edf,erg,',',rgr,rgr I have a requirement like i have to extract different field and assign them into different... (4 Replies)
Discussion started by: J.Jena
4 Replies

2. Shell Programming and Scripting

Convert fixed value fields to comma separated values

Hi All, Hope you are doing Great!!!. Today i have came up with a problem to say exactly it was for performance improvement. I have written code in perl as a solution for this to cut in specific range, but it is taking time to run for files thousands of lines so i am expecting a sed... (9 Replies)
Discussion started by: mad man
9 Replies

3. Shell Programming and Scripting

Correct incomplete fields separated by new lines

Hello Friends, I have an issue with a csv file that is separated by comma. The file should have 5 fields every time. The record delimiter of the file is \r\n but we are seeing that in few records the address field has \r\n too in them which is causing the line to break into two or more lines. ... (3 Replies)
Discussion started by: mehimadri12
3 Replies

4. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

5. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

6. Shell Programming and Scripting

AWK:Split fields separated by semicolon

Hi all, I have a .vcf file which contains 8 coulmns and the data under each column as shown below, CHROM POS ID REF ALT QUAL FILTER INFO 1 3000012 . A G 126 ... (6 Replies)
Discussion started by: mehar
6 Replies

7. Shell Programming and Scripting

Compare files with fields separated with semicolon

Dear experts I have files like ABD : 5869 events, relative ratio : 1.173800E-01 , sum of ratios : 1.173800E-01 VBD : 12147 events, relative ratio : 2.429400E-01 , sum of ratios : 3.603200E-01 SDF : 17000 events, relative ratio : 3.400000E-01 , sum of ratios : 7.003200E-01 OIP: 14984... (9 Replies)
Discussion started by: Alkass
9 Replies

8. Shell Programming and Scripting

Compare Tab Separated Field with AWK to all and print lines of unique fields.

Hi. I have a tab separated file that has a couple nearly identical lines. When doing: sort file | uniq > file.new It passes through the nearly identical lines because, well, they still are unique. a) I want to look only at field x for uniqueness and if the content in field x is the... (1 Reply)
Discussion started by: rocket_dog
1 Replies

9. Shell Programming and Scripting

Parse apart strings of comma separated data with varying number of fields

I have a situation where I am reading a text file line-by-line. Those lines of data contain comma separated fields of data. However, each line can vary in the number of fields it can contain. What I need to do is parse apart each line and write each field of data found (left to right) into a file.... (7 Replies)
Discussion started by: 2reperry
7 Replies

10. UNIX for Dummies Questions & Answers

Remove whitespaces between comma separated fields from file

Hello all, I am a unix dummy. I am trying to remove spaces between fields. I have the file in the following format 12332432, 2345 , asdfsdf ,100216 , 9999999 12332431, 2341 , asdfsd2 ,100213 , 9999999 &... (2 Replies)
Discussion started by: nitinbjoshi
2 Replies
Login or Register to Ask a Question