guys! I am trying to exchange two words in a line but it doesn\'t work. For example: \"Today is my first day of university\" should be \"my is Today first day of university\"
sed -r 's/^(\w+)(\s+\w+\s+)(\w+)(.*)/\3\2\1\4/'
with your example:
kent$ echo "Today is my first day of university"|sed -r 's/^(\w+)(\s+\w+\s+)(\w+)(.*)/\3\2\1\4/'
my is Today first day of university
for your problem, awk is more straightforward:
awk '{t=$1;$1=$3;$3=t}1'
same input:
kent$ echo "Today is my first day of university"|awk '{t=$1;$1=$3;$3=t}1'
my is Today first day of university