- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Using VI to insert line from bash script
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
Discussions
Discussions
Forums
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
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
тАО10-20-2008 06:00 AM
тАО10-20-2008 06:00 AM
Good day,
I would like to write a sh script that insert a line in a file BUT I keep getting "Input read error"
This is my try :
vi a << EOF
:i
insert
^[
EOF
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2008 06:24 AM
тАО10-20-2008 06:24 AM
Re: Using VI to insert line from bash script
HTH
Duncan
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2008 07:55 AM
тАО10-20-2008 07:55 AM
Re: Using VI to insert line from bash script
Thanks for reply,
I have a file containing certain value X. About this value in four lines there is value Y I want to take Y and put instead X. And shift the lines one line below.
For Example :
1 junk data
2 junk data
3 Y
4 junk data
5 junk data
6 junk data
7 X
8 junk data
I want to do the following :
1 junk data
2 junk data
3 Y
4 junk data
5 junk data
6 junk data
7 Y
8 OLD X Updated
9 junk data
So I wrote the following as part of my shell script : "I have Y value in variable Z"
vi FILE << EOF
:7
:O
$Z
^[
:j
:xx
:wq!
EOF
-----------------
This is what I want. but it seams not working even if I want only to do this :
vi FILE << EOF
:7
:O
$Z
^[
:ZZ
EOF
Any help?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2008 08:02 AM
тАО10-20-2008 08:02 AM
Re: Using VI to insert line from bash script
$ perl -pi -e'/^X$/ and $_ .= "\n$ENV{Z}\n"' FILE
Enjoy, Have FUN! H.Merijn
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2008 10:16 AM
тАО10-20-2008 10:16 AM
Re: Using VI to insert line from bash script
$ awk '/X/{print line[(NR-4)%10]; $0 = "old " $0} {line[NR%10] = $0; print}' x
In slow motion:
/X/ { # if you see a line marked 'X' then
print line[(NR-4)%10]; # Pick up 4 lines ago from secret stash, and
$0 = "old " $0} # munge current line
{ # for each line
line[NR%10] = $0; # put in stash (circular buffer), and
print} # print current line (may be modified)
' x # input from a file called x
I used a 10 element circular buffer using a MODULUS function just for grins, to make clear where the '4 lines above' goes.
Using 5 elements would of course be enough.
hth,
Hein.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2008 10:21 AM
тАО10-20-2008 10:21 AM
Re: Using VI to insert line from bash script
I have to try them tomorrow. I have only one point to mention that X value it's not unique, it will be repeated over and over in the file.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2008 10:37 AM
тАО10-20-2008 10:37 AM
Re: Using VI to insert line from bash script
Is that what was intended, Did you want to pick up only a first 'Y' and repeat that?
Of course you should replace 'X' Regular Expression which does nto generate false positive. Anchoring the string often helps a lot with that: For example /^X/ to recognize X only when at the very start of a line.
To get better help, please try to explain more clearly how to recognize the lines with 'X' and 'Y'.
By contents?
By contents of lines around them?
By (relative) record number?
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-20-2008 12:59 PM
тАО10-20-2008 12:59 PM
Re: Using VI to insert line from bash script
If you want only the first, you need a guard
$ perl -pi -e'/^X$/&&$ENV{Z}and$_.="\n".delete$ENV{Z}."\n"' FILE
Enjoy, Have FUN! H.Merijn [ who loves dirty trickery and one-liners ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2008 02:12 AM
тАО10-21-2008 02:12 AM
Re: Using VI to insert line from bash script
Thanks for reply, I'm sorry but the hole concept changed today,
this is a real data
,10:1
,11:1
,14:1001
17,10:1
,11:0
,12:0
I want to replace each "17,10:1" to "17,9:1/E" and insert a new line under it with a value ",10:1"
So, how can I do this with awk ?
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2008 02:46 AM
тАО10-21-2008 02:46 AM
Re: Using VI to insert line from bash script
I wrote this in sed, I have to put it in sh script.
sed '
/^17,10:1$/ a\
,10:1
s#^17,10:1$#17,9:5/E#g'
It's work, Any more powerful Ideas ?
- Tags:
- sed