Redirecting output of pipe operator to a variable
I am using unix power tools to search for a content in a file and replace the content with sed command.
I am using the following command to achieve this
grep user ora | awk -F@ ' { print $1 } ' | awk -F= ' { print $2 } ' | cut -c 2- | xargs sed 's/user3/user/'
The contents of ora is as follows:
cat ora
user="user3@ghy" pass="ghy"
Every time the username will be different in 'ora' file. Different in the sense that user will remain same , the numeric part will change. e.g user1 , user2 , user3 etc .
Now I want that this username pattern will be replaced by fixed username namely 'user' .
grep user ora | awk -F@ ' { print $1 } ' | awk -F= ' { print $2 } ' | cut -c 2- | sed 's/<pattern>/user/'
I am using xargs command to achieve the result , but it is not working
grep user ora | awk -F@ ' { print $1 } ' | awk -F= ' { print $2 } ' | cut -c 2- | xargs sed -i 's//user/'
sed: can't read user3: No such file or directory
How to read this <pattern> dynamically.
Last edited by zama; 02-03-2015 at 03:06 AM.
|