Link to home
Start Free TrialLog in
Avatar of joaotelles
joaotellesFlag for United States of America

asked on

Shell - appending string at beginning of each text file line

Hi,

I have a text file that has very long string in each line that go through another line as shown below...

"RIS" -inst="ris1a" "Corba/OAIAddr" "demo-app-01" -type=STRING -description="The hostname or ip address for the machine on which RPAOSNIS is running." -visibility=INSTANCE

So, I have to append  a string at the beginning of each line (rtool -w)..

The file has many lines so I come up with this command:
sed "s/^/rtool -w /" file_1 > file_2

But file_2 is getting the rtool -w in all the lines... whenever there is a break in the line...

rtool -w "RIS" -inst="ris1a" "Corba/OAIAddr" "demo-app-01" -type=STRING -description="The hostname or ip address for the machine on which
rtool -w RPAOSNIS is running." -visibility=INSTANCE

===

Is there anything to prevent it?

Tks,
Joao
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Do all of the lines you want to change start with "RIS"?  If so

    sed 's/^"RIS"/rtool -w "RIS"/' file1 > file2
Avatar of joaotelles

ASKER

No... The beginning of each line can vary....

Tks,
Joao
But is there some consistency?  Is it always a double quote folowed by capital letters followed by another double quote?  is there always a '"-inst=" bit immediately following the first word?

If there is no way to identify a line which needs the "rtool -w " prefix, then it will be hard to automate this.
Here are more lines of the file that might answer your questions.

"JamAssistant" -inst="jamat1a" "Sso/Service/BaseUrl" "https://iot-app-01:8443/jamassistant" -type=STRING -description="The base URL of the application" -visibility=INSTANCE
"JamServer" -inst="jam1a" "Network/HostName" "iot-app-01" -type=STRING -description="The hostname or IP-address for the machine on which the JamServer is running." -visibility=INSTANCE
"Mdm" -inst="mdm1a" "Network/HostName" "iot-app-01" -type=STRING -description="The hostname or ip address for the machine on which MDM is running. All processes acting as clients to MDM shall use t
his parameter." -visibility=INSTANCE
"SmartManage" -inst="sm1a" "Network/HostName" "iot-app-01" -type=STRING -description="The hostname or ip address for the machine on which SmartManage is running. All processes acting as clients to
SmartManage shall use this parameter." -visibility=INSTANCE
"RIS" -inst="ris1a" "Network/ITerminalCapabilitiesCorbaloc" "corbaloc:iiop:iot-app-01:10152/ris1a/Tcr/ITerminalCapabilities" -type=STRING -description="Corbaloc object reference to Terminal Capabil
ities API-object, automatically assigned by the server." -visibility=INSTANCE
"TransportServer" -inst="ts1a" "Network/HostName" "iot-app-01" -type=STRING -description="The hostname or ip-address for the machine on which the Transport server is\nrunning. All processes acting
as clients to the Transport Server use this\nparameter." -visibility=INSTANCE
"WigServer" -inst="wig1a" "Network/HostName" "iot-app-01" -type=STRING -description="The hostname or ip-address for the machine on which the Wig server is running." -visibility=INSTANCE
ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tks.