I have a text file that contains:
toto.titi.any=val1
toto.tata.any=val2
toto.tete.any=val2
How to extract titi
, tata
and tete
from this file.
Should be some sthing like that
$ cat myfile.txt | sed '......'
and the output should be
titi
tata
tete
Do you really need sed
? You could use cut
:
cut -d. -f2 filename
With awk you can do:
awk -F. '{print $2}' file
awk/cut would be better choice for this problem.
here is the sed line and grep option:
sed -r 's/.*\.([^.]*)\..*/\1/'
grep -Po '\.\K[^.]*(?=\.)'
awk
and cut
are best for this
you can also read the file line by line, and print out the portion needed.
$ IFS=.
$ while read first interested others ; do echo $interested; done < file
titi
tata
tete
sed -n 's/^[^.]*.\([^.]*\)..*/\1/p' myfile.txt
display second value between dot from line having at least 2 dot inside