Operating System - HP-UX
1751797 Members
5114 Online
108781 Solutions
New Discussion юеВ

Re: Using VI to insert line from bash script

 
SOLVED
Go to solution
Hein van den Heuvel
Honored Contributor
Solution

Re: Using VI to insert line from bash script

>> 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 ?

yes, but WHY?

awk '/^17,10:1/ {gsub (/,/, ",9.5/E\n,")} {print} ' x

>> It's work, Any more powerful Ideas ?

Only if you describe in a powerful way where the 17 and the 9.1 (9.5) and such come from.
Are they really just fixed strings, always the same? That is a totally boring case. Just pick a solution and be happy.

Cheers,
Hein.
AZayed
Super Advisor

Re: Using VI to insert line from bash script

Hi Hein,

My customer changed his idea so I had to change my work. And yes, it's easy one.

But in your awk command, you didn't insert ",10:1" value.

Last thing before I close this case, do you recommend a useful awk and sed from personal experiences?

Thanks :)
Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.
AZayed
Super Advisor

Re: Using VI to insert line from bash script

Hi Hein,

It seems your line working great. although, I didn't notice that you wrote ",10:1" in your line. But your awk line doing what I want do do. It's amazing :)

I want to learn how to use awk because this line is more powerful than complex bash script.

Thanks
Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.
James R. Ferguson
Acclaimed Contributor

Re: Using VI to insert line from bash script

Hi:

If you want to start with 'awk' you could use this free, but excellent guide:

http://www.gnu.org/software/gawk/manual/gawk.html

Be aware that the GNU variant is a bit more powerful than HP's or AIX's standard.

Regards!

...JRF...
AZayed
Super Advisor

Re: Using VI to insert line from bash script

Thanks JRF,

Thanks folks for your support.

Have a nice day.
Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.
AZayed
Super Advisor

Re: Using VI to insert line from bash script

Yes,

It's awk command. It's powerful.

awk '/^17,10:1$/ { gsub (/,/, ",9:5/E\n,") } { print }'
Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.
Hein van den Heuvel
Honored Contributor

Re: Using VI to insert line from bash script

>> It seems your line working great. although, I didn't notice that you wrote ",10:1" in your line. But your awk line doing what I want do do. It's amazing :)

I did't write ,10:1. That was already there :-).
I just stuck a new-line ( \n ) in front of it.

I wrote my solution in anticipation of future, other needs. That's was seperates solutions from hacks.
My assumption was that you did not want "10:1" but "whatever was on the old line after the comma"... which happens to be 10:1 for now.
Similar for the 17. I left the value itself on the line, using it only as a simple regular expression untill you explained better where the 17 came from.
I only replaced the comma, not the values.

Try this:

$ awk '/^[0-9]+,/ {gsub (/,/, ",9.5/E\n,")} {print} ' x

... no 17, no 10, and yet...


>> I want to learn how to use awk because this line is more powerful than complex bash script.


I was hoping that, and that's why I providede the blow-by-blow breakdown in my first example. Try to follow that!

Cheers,
Hein.
Dennis Handly
Acclaimed Contributor

Re: Using VI to insert line from bash script

As Duncan said, you can't use vi. You can use sed(1), awk(1), perl(1), ed(1) or ex(1).

Your example above would be:
ex a << EOF
i
insert data
.
wq
EOF