Dealing with Linux servers
script would be in korn or bash shell syntax
file is /etc/fstab
I want to insert something if regex is matched to all matched lines in the /etc/fstab file and print out entire /etc/fstab file with the changes
example
58.228.111.111:/my/file/system /my/file/system nfs rw,soft,bg,intr,vers=3 0 0
if uncommented line starts with 58. "^58\."
and line doesn't contain FOO
and line doesn't contain BOO
and if the line meets these requirements, insert the word BAR in a certain location
finished line would look like this
58.228.111.111:/BAR/my/file/system /my/file/system nfs rw,soft,bg,intr,vers=3 0 0
one line that comes close is this
sed -e '/THIS/!s/\:\//\:\/BAR\//g'
This of course is my first attempt which doesn't work but it does kinda show
you what I am looking for
grep "^58\." /etc/fstab |egrep -v "FOO|BOO" |sed -e "s/\:\//\:\/BAR\//g"
so my question is 2 part
- how can I change a line like this
58.228.111.111:/my/file/system /my/file/system nfs rw,soft,bg,intr,vers=3 0 0
to this
58.228.111.111:/BAR/my/file/system /my/file/system nfs rw,soft,bg,intr,vers=3 0 0
- I don't understand how this is working
sed -e '/THIS/!s/\:\//\:\/BAR\//g'
I understand that "!s" section is saying don't look at lines with THIS in it
in general this is using a SED command, using a regex to throw out 2 seperate expressions, and include one regex.
sed '/^58\./,/FOO/!s//BAR/g' /etc/fstab
close, but no cigar