Trying to Parse Version Information from Text File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to Parse Version Information from Text File
# 1  
Old 01-28-2010
Trying to Parse Version Information from Text File

I have a file name version.properties with the following data:

major.version=14
minor.version=234

I'm trying to write a grep expression to only put "14" to stdout. The following is not working.

grep "major.version=([0-9]+)" version.properties

What am I doing wrong?
# 2  
Old 01-28-2010
Try egrep.
# 3  
Old 01-28-2010
That's progress, but egrep returns "major.version=14" ... I only want the 14.
# 4  
Old 01-28-2010
Try:
Code:
sed 's/major\.version=\([0-9]\+\)/\1/'

-or-
Code:
sed 's/major\.version=\([0-9]\{1,\}\)/\1/'

-or-
Code:
sed -r 's/major\.version=([0-9]+)/\1/'

-or-
Code:
awk -F= '$1=="major.version"{print $2}'

# 5  
Old 01-28-2010
I tried all four of those. I'm using cygwin's sed and awk. The first three returned everything after the first equal sign. The awk statement returned nothing at all.

D:\>sed 's/major\.version=\([0-9]\+\)/\1/' version.properties
14
minor.version=234

D:\>sed 's/major\.version=\([0-9]\{1,\}\)/\1/' version.properties
14
minor.version=234

D:\>sed -r 's/major\.version=([0-9]+)/\1/' version.properties
14
minor.version=234

D:\>awk -F= '$1=="major.version"{print $2}' version.properties

---------- Post updated at 02:22 PM ---------- Previous update was at 02:15 PM ----------

gawk works beautifully. Thank you.

---------- Post updated at 02:30 PM ---------- Previous update was at 02:22 PM ----------

Is there any way to get the awk command to print "14.234"?
# 6  
Old 01-28-2010
Oops, that should be:
Code:
sed -n 's/major\.version=\([0-9]\+\)/\1/p'

-or-
Code:
sed -n 's/major\.version=\([0-9]\{1,\}\)/\1/p'

-or-
Code:
sed -nr 's/major\.version=([0-9]+)/\1/p'



---------- Post updated at 20:44 ---------- Previous update was at 20:33 ----------

Quote:
Originally Posted by obfunkhouser

Is there any way to get the awk command to print "14.234"?
Code:
awk -F= '$1=="major.version"{a=$2}$1=="minor.version"{b=$2}END{print a"."b}'

# 7  
Old 01-28-2010
That's awesome. Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script to parse and compare information in two fields of file

Hello, I am working parsing a large input file1(field CFA) I have to compare the the file1 field(CFA byte 88-96) with the content of the file2(It contains only one field) and and insert rows equal in another file. Here is my code and sample input file: ... (7 Replies)
Discussion started by: GERMANOS
7 Replies

2. Shell Programming and Scripting

awk script to parse case with information in two fields of file

The below awk parser works for most data inputs, but I am having trouble with the last one. The problem is in the below rules steps 1 and 2 come from $2 (NC_000013.10:g.20763686_20763687delinsA) and steps 3 and 4 come from $1 (NM_004004.5:c.34_35delGGinsT). Parse Rules: The header is... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

Parse text file using specific tags

awk -F "" '/<href=>|<href=>|<top>|<top>/ {print $3, OFS=\t}' source.txt > output.txt I'm not quite sure how to parse the attached file, but what I am trying to do is in a output file have the link (href=), name (after the <), and count (<top>) in 3 separate columns. My attempt is the above... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. UNIX for Dummies Questions & Answers

Inserting information from old text file into a new text file

Hello, I'm trying to take information from a list of hundreds of subject ids (where each line is a new subject id), and insert each line into a new text file that contains the pathnames for each subject. To clarify, all subject have a similiar path name (e.g., C:\data\SUBJECT_ID\) that contains... (4 Replies)
Discussion started by: invisibledwarf
4 Replies

5. Shell Programming and Scripting

Parse and Join in a text file

I wanted to parse a text file and join in specific format. please suggest me how to get this done.. The output should be in fasta format which consists of lines starting with ID, PT, PA and Sequence. "//" the two slashes are dividing lines between two different sequences. Like... (10 Replies)
Discussion started by: empyrean
10 Replies

6. Shell Programming and Scripting

How to parse a file for text b/n double quotes?

Hi guys, I desperately need some help here... I need to parse a file similar to this: I need to read the values for MY_BANNER_SSHD and WARNING_MESSAGE. The value could be empty/single line or multi-line! # Comments . . . Some lines MY_BANNER_SSHD=""... (7 Replies)
Discussion started by: shreeda
7 Replies

7. UNIX for Dummies Questions & Answers

parse through one text file and output many

Hi, everyone The input file pattern is like below: Begin Object1 txt1 end ; Begin Object2 txt2 end ; ... (14 Replies)
Discussion started by: sophiadun
14 Replies

8. Shell Programming and Scripting

parse text file

I have a file that has a header followed by 8 columns of data. I want to toss out the header, and then write the data to another file with a different header and footer. I also need to grab the first values of the first and second column to put in the header. How do I chop off the header? ... (9 Replies)
Discussion started by: craggm
9 Replies

9. Shell Programming and Scripting

parse text file

i am attempting to parse a simple text file with multiple lines and four fields in each line, formatted as such: 12/10/2006 12:34:06 77 38 this is what i'm having problems with in my bash script: sed '1,6d' $RAWDATA > $NEWFILE #removes first 6 lines from file, which are... (3 Replies)
Discussion started by: klick81
3 Replies

10. UNIX for Dummies Questions & Answers

Parse Text file and send mails

Please help. I have a text file which looks something like this aaa@abc.com, c:FilePath\Eaaa.txt bbb@abc.com, c:FilePath\Ebbb.txt ccc@abc.com, c:FilePath\Eccc.txt ddd@abc.com, c:FilePath\Eddd.txt...so on I want to write a shell script which will pick up the first field 'aaa@abc.com' and... (12 Replies)
Discussion started by: Amruta Pitkar
12 Replies
Login or Register to Ask a Question