- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- replacing a line of file with a line from another ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2003 04:31 AM
09-17-2003 04:31 AM
replacing a line of file with a line from another file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2003 04:37 AM
09-17-2003 04:37 AM
Re: replacing a line of file with a line from another file
#!/bin/sh
LINE2=$(grep "line I need" file2)
sed "s/pattern/$LINE2/" file1 > file3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2003 04:54 AM
09-17-2003 04:54 AM
Re: replacing a line of file with a line from another file
i have tried that usind sed but the error which i am getting is that pattern canot be parsed.The problem is
I have one of the user entries in passwd file ( all the 7 fields ) in one passwd file
say
oracledb:*:11:11::/var/spool/uucppublic:/usr/lbin/uucp/uucico
Now i have constructed a line
Xoracleb:*NP* :11:11:user disabled :/var/spool/uucppublic:/bin/false
using script now i wanna replace the constructed line which is there in my o/p file with the line matching "^oracledb" in the start of the line .
Note:I do not want to replace just "oracledb "
I guess sed gave me the error because the variable was long
i tried the following using sed
sed ' /'$orgvar`/ {
s/'$orgvar'/'$newvar'/
}' datafile
where $orgvar contains the old line and $newvar contains the new line which has to come in place of old line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2003 05:07 AM
09-17-2003 05:07 AM
Re: replacing a line of file with a line from another file
In a previous thread I mentioned the use of vi
have a look at it :
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x38fa82eced96bc409e0e67b4869c642d,00.html
Rgds,
JL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2003 06:31 AM
09-17-2003 06:31 AM
Re: replacing a line of file with a line from another file
is there a way to parse a shell variable in vi with can be given as $var for search patterns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2003 06:49 AM
09-17-2003 06:49 AM
Re: replacing a line of file with a line from another file
awk -Vorg="$orgvar" -Vnew="$newvar" '{if $0 == $org then print $new else print $0}'
Not sure your full intent here. Are you planning on changing multiple passwd files or are their multiple entries within one passwd file.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2003 07:00 AM
09-17-2003 07:00 AM
Re: replacing a line of file with a line from another file
Same apply to awk.
Therefore, as mentioned in the previous thread thr "trick" is to position the cursor in the file and import an external file.
Rgds,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2003 07:29 AM
09-17-2003 07:29 AM
Re: replacing a line of file with a line from another file
Example:
sed 's@find@replace@' < file1 > file2
To replace a line in one file with a line from another file - try:
(With sed)
----
#!/bin/sh
# 'file' is the file to be changed
# 'template' is a file containing strings to replace with
# 'find' is the string to search for
# 'repl' is part of the string to replace with
find=$1; template=$2; find=$3; repl=$4
replace=`grep "$repl" $template`
sed "/$find/s@@$replace@" $file > /tmp/$file.$$
mv /tmp/$file.$$ $file
----
invoke as:
script
Better is to use 'ed' (if you use the above method, you might lose permission settings on the original file depending on umask settings).
(with ed)
----
#!/bin/sh
file=$1; template=$2; find=$3; repl=$4
replace=`grep "$repl" $template`
ed - $file <
$replace
.
w
de
----
Happy scripting!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2003 03:05 PM
09-17-2003 03:05 PM
Re: replacing a line of file with a line from another file
sed indeed will error out if / is in the string.
I have successfully done this by simply escaping the / with a \ in the string.
i.e. string="\/home\/someone\/or_something"
Best of luck.
Regards,
dl