Extract information from a .txt file

3

I have a .txt file with the following information.

31.812:9.862 179.52:6.847 315.015:9.135 462.305:6.276
103.875:4.122 176.064:3.593 196.7:4.407 246.599:4.423

I need to extract this information

9.862 6.847 9.135 6.276 
4.122 3.593 4.407 4.407

(that is, the values that are between the: and space)

    
asked by anonymous 25.01.2017 / 19:23

3 answers

5

You can use the tr command to replace the : with and then use the cut command to select only the even columns.

Ex:

cat arquivo.txt | tr ':' ' ' | cut -d' ' -f2,4,6,8

TR : Replace all colon with space

CUT :

  • -d : Defines the space as a field delimiter
  • -f : Select only the fields 2, 4, 6, and 8 that are the numbers you are interested in.

file.txt

31.812:9.862 179.52:6.847 315.015:9.135 462.305:6.276
103.875:4.122 176.064:3.593 196.7:4.407 246.599:4.423

output

9.862 6.847 9.135 6.276
4.122 3.593 4.407 4.423
    
25.01.2017 / 20:18
3

Use regular expressions to perform the necessary extraction of the file .txt , to get what you need I used the following expression: : \ d. \ d {3}

Test here

    
25.01.2017 / 19:48
2
sed -r 's/[^ ]+:([^ ]+)//g' arquivo.txt
    
29.01.2017 / 10:27