0

I have a text line that looks like this (there is a space after "poseidon"):

/usr/share/geoserver/data_dir/workspaces/poseidon public/odense_kommune/datastore.xml:17:host">a-postgis1.gues.com</entry>

and I use this to delete everything after the first ":"

filename=$(sed 's/\:.*$//' <<< $myHost)

The result is :

/usr/share/geoserver/data_dir/workspaces/poseidon
public/datastore.xml

and it should have been :

/usr/share/geoserver/data_dir/workspaces/poseidon public/datastore.xml

it replaces the space with with a new line

I have tried with several SED options but can't figure out what is wrong.

I use the above like this :

filename=$(sed 's/\:.*$//' <<< $myHost)
echo Filnavn : $filename >> filn.txt
neurino
  • 1,819
  • 3
  • 19
  • 25
Julian
  • 1

3 Answers3

2

Your sed command works for me.

But no need for sed, you can use shell parameter expansion to remove everything from the first : to the end:

filename=${myHost%%:*}
pLumo
  • 22,565
0

Use cut instead :

cut -d ':' -f 1

Will select all before the first :.

MUY Belgium
  • 1,255
0

Your sed command works for me.

$ cat test 
/usr/share/geoserver/data_dir/workspaces/poseidon public/odense_kommune     /datastore.xml:17:host">a-postgis1.gues.com</entry>

SED

$ cat test  | sed 's/\:.*//'
/usr/share/geoserver/data_dir/workspaces/poseidon public/odense_kommune/datastore.xml

If you can't use sed to solve this problem, you can try cut or awk.

CUT

$ cat test  | cut -d ':' -f1
/usr/share/geoserver/data_dir/workspaces/poseidon public/odense_kommune/datastore.xml

AWK

$ cat test  | awk -F ':' '{printf $1}'
/usr/share/geoserver/data_dir/workspaces/poseidon public/odense_kommune/datastore.xml
zsnmwy
  • 1