05-18-2008
PERL: add string to multiple lines
Dear all,
I am stuck while trying to add a string to multiple lines. Let me try to explain using an example:
Input:
--------
myExample_send ("MasterSends",
n,
"Data Type",
MPI_INT);
correct Output:
-----------------
#pragma my my_Example_send ("MasterSends",
#pragma my n,
#pragma my "Data Type",
#pragma my MPI_INT);
I search for "myExample_" and want to replace it with "#pragma my myExample_". My perl script works fine if the function call doesn't exceed one line. See below a section of the perl script I use:
******************************************
# Original string
$original = "myExample_";
# New string
$replacement = "#pragma my myExample_";
undef $/;
# Open each file otherwise print error message
foreach $file (@ARGV)
{
if ( ! open(INPUT,"<$file") )
{
print STDERR "Can't open file $file\n";
next;
}
# Read input file as one long record
$data=<INPUT>;
close INPUT;
# replace original string with new string
if ( $data =~ s/$original/$replacement/gi )
{
....
}
}
******************************************
However, if the function call exceeds one line, then obviously I get something similar to:
Current Output:
------------------
#pragma my myExample_send ("MasterSends",
n,
"Data Type",
MPI_INT);
Which would result in an error while compilation.
Can anybody "coach" me how to add "#pragma my " to all lines belonging to the myExample_send function call?
Thanks a lot in advance!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi Gurus,
I need some help with the "grep" command or whatever command that you think suitable for me. I'm about to write a perl script to extract a report from the system and submit it to the end users. The input for the script will consist of 3 element.
1) Generation ID
2) Month
3) Year... (6 Replies)
Discussion started by: miskin
6 Replies
2. Shell Programming and Scripting
Hi All,
I need your help to solve problem using either PERL script or SHELL script.
We are receving a file, in which one record is coming in multiple rows. The main problem is, we are not able to differenciate when the 1st record ends and where the second record starts.
For example,
... (4 Replies)
Discussion started by: Amit.Sagpariya
4 Replies
3. Shell Programming and Scripting
I'd like to do this using Perl command line (sorry no awk, sed, etc.)
replace the 3 middle lines in a file by one line:
aaa 123
bbb 234
ccc 34567
dd 4567
ee 567
to:
aaa 123
AAA
ee 567
I tried this but not working:
perl -pi -e "s/aaa\ 123\nbbb\ 234\nccc\ 34567/AAA/" file (2 Replies)
Discussion started by: tintin78899
2 Replies
4. Shell Programming and Scripting
Can someone tell me how I can do this?
e.g:
Say file1.txt contains:
today is monday
the 22 of
NOVEMBER
2010
and file2.txt contains:
the
11th
month
of
How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies
5. Shell Programming and Scripting
Can someone tell me how I can do this?
e.g:
a=$(echo -e wert trewt ertert ertert ertert erttert
erterte
rterter
tertertert
ert)
How do i replace the STRING with $a?
I try this:
sed -i 's/STRING/'"$a"'/g' filename.ext
but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies
6. Shell Programming and Scripting
hey guys,
I tried searching but most 'search and replace' questions are related to one liners.
Say I have a file to be replaced that has the following:
$ cat testing.txt
TESTING
AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
ENDTESTING
This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies
7. Shell Programming and Scripting
Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ?
The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories.
So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies
8. Shell Programming and Scripting
Hello,
I will be sending this command to a specific COMID:
exp_send-i $COMID "fdisk -l | grep Disk | awk '{print $2}'"
The command will produce this output:
/dev/sda
/dev/sdb
etc..
the problem is how do I store the output in a variable in TCL,
I am currently using this to grab the... (1 Reply)
Discussion started by: h0ujun
1 Replies
9. Shell Programming and Scripting
Hi,
I have a file containing the DDLs of tables in a schema. From that I need to remove all the lines from a starting string till a specific string. Here is an example.
File1.txt
-------------
CREATE TABLE "SCHEMA1"."LKP11_TBL_USERS"
( "ID" NUMBER(8,0) NOT NULL ENABLE,
"USER_ID"... (3 Replies)
Discussion started by: satyaatcgi
3 Replies
10. Shell Programming and Scripting
Hello Guys,
I need to replace a string with multiple lines.
For eg:-
ABC,DEF,GHI,JKL,MNO,PQR,STU
need to convert the above as below:-
ABC,DEF,
GHI1
GHI2
GHI3,
JKL,MNO,
PQR1
PQR2
PQR3,
STU
i have tried using code as:- (2 Replies)
Discussion started by: jassi10781
2 Replies
LEARN ABOUT HPUX
fegetenv
fegetenv(3M) fegetenv(3M)
NAME
fegetenv() - get floating-point environment
SYNOPSIS
HP Integrity Server Only
PA-RISC Only
DESCRIPTION
The function stores the current floating-point environment in the object pointed to by the argument envp.
To use this function, compile either with the default option or with the and options.
Make sure your program includes
For Integrity servers, specify on the compiler command line or place the call to this function under the effect of an affirmative pragma:
If the pragma is placed outside of any top-level declarations in a file, the pragma will apply to all declarations in the compilation fol-
lowing the pragma until another pragma is encountered or until the end of the file is reached.
If the pragma is placed at the beginning of a block (compound statement), the pragma will apply until another pragma is encountered or
until the end of the block is reached.
For PA-RISC, you might need to use the +Onomoveflops compiler option in order to prevent optimizations that can undermine the specified
behavior of this function.
Link in the math library by specifying on the compiler or linker command line.
For more information, see the at the following site:
RETURN VALUE
Integrity Server Only
This function always returns 0, indicating that a representation of the current environment was successfully stored.
PA-RISC Only
None.
ERRORS
No errors are defined.
EXAMPLES
Store the current floating-point environment:
SEE ALSO
feholdexcept(3M), fesetenv(3M), feupdateenv(3M), fenv(5).
STANDARDS CONFORMANCE
: ISO/IEC C99 (including Annex F, "IEC 60559 floating-point arithmetic")
fegetenv(3M)