1

So i got a text file which looks like this

# begin build properties
# autogenerated by buildinfo.sh
ro.build.id=LRX21T
ro.build.version.incremental=G900FXXU1BOK6
ro.build.version.sdk=21
ro.build.version.codename=REL
ro.build.version.all_codenames=REL
ro.build.version.release=5.0
ro.build.version.security_patch=2015-11-01
ro.build.version.base_os=
ro.build.date=Mon Nov 23 14:29:35 KST 2015
ro.build.date.utc=1448256575
ro.build.type=user
ro.build.user=dpi
ro.build.host=SWHD4408
ro.build.tags=release-keys
ro.product.model=SM-G900F
ro.product.brand=samsung
ro.product.name=kltexx
ro.product.device=klte
ro.product.board=MSM8974
# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,
# use ro.product.cpu.abilist instead.
ro.product.cpu.abi=armeabi-v7a
ro.product.cpu.abi2=armeabi
ro.product.cpu.abilist=armeabi-v7a,armeabi
ro.product.cpu.abilist32=armeabi-v7a,armeabi
ro.product.cpu.abilist64=
ro.product.manufacturer=samsung
....

What i want are the lines

  • ro.product.model=SM-G900F
  • ro.build.version.incremental=G900FXXU1BOK6

but not complete, only what comes after = so SM-G900F and G900FXXU1BOK6.

I know this can be done some way, either with awk or grep but i don't know how exactly. Thanks a lot

4 Answers 4

1

With GNU sed:

sed -n 's/^ro.product.model=//p;s/^ro.build.version.incremental=//p' file

or

sed -nr 's/^(ro.product.model|ro.build.version.incremental)=//p' file

Output:

G900FXXU1BOK6
SM-G900F

or with current GNU bash:

#!/bin/bash

while read -r line; do
  [[ $line =~ ^(ro.product.model=) ]] && r="${line#*${BASH_REMATCH[1]}}"$'\n'"$r"
  [[ $line =~ ^(ro.build.version.incremental=) ]] && r="${line#*${BASH_REMATCH[1]}}"
done < file
echo "$r"

Output:

SM-G900F
G900FXXU1BOK6
2
  • I've updated the bash part. Commented Feb 28, 2016 at 10:15
  • Had to modify a bit to show like this (Model: SM-G900F / Build: G900FXXU1BOK6) but as i did not state this in my question it's clearly my fault. Nonetheless this works as expected, thank you very much Commented Feb 28, 2016 at 10:23
1

Use grep to match the line and cut to select the part you want:

grep ro.product.model input.txt |cut -d= -f2

The -d option set = as separator and the -f option select the second field.

1
  • i like that you explained the options set. take an upvote (as soon as i got 15 rep) Commented Feb 28, 2016 at 10:00
0

Use below command it will give you the result :

egrep 'ro.product.model|ro.build.version.incremental' a.txt | awk -F'=' '{print $2}'

egrep is as same as grep -e and is used here to search multiple expression as the same time. Awk is just doing the extracting the data after "="

G900FXXU1BOK6

SM-G900F

0
awk -F= '$1 ~ /^(ro.product.model|ro.build.version.incremental)$/ { print $2 }' 

Using a field delimiter of =, print the second field only if the first field matches the regexp pattern ^(ro.product.model|ro.build.version.incremental)$

1
  • probably should use \. (which matches only literal .) rather than plain . (which matches any character), but in this case, it makes no difference. i.e. ^(ro\.product\.model|ro\.build\.version\.incremental)$ Commented Feb 29, 2016 at 0:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.