removing \n in PERL from the data fetched from db


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing \n in PERL from the data fetched from db
# 1  
Old 03-09-2012
removing \n in PERL from the data fetched from db

Hi

I am fetching data from table which contains SQL query like this into a variable $qry


Code:
SELECT ABC,
DEF
WHERE (XYZ = 'Normalization' or 
ABC_TYPE = 'DEF') and lookup_port like 'ABAC%'

My requirement is I need to fetch a where clause to a variable

Code:
if ( $qry =~ m/(where.*)/i)
{
print $1;
}

I am getting the o/p as WHERE (XYZ = 'Normalization' or
but

Expected o/p is

Code:
WHERE (XYZ = 'Normalization' or 
ABC_TYPE = 'DEF') and lookup_port like 'ABAC%'

Thanks
gvk

---------- Post updated at 04:31 PM ---------- Previous update was at 04:26 PM ----------

when I tried this

Code:
$qry =~ s/\n/ /g;

I am getting below o/p

Code:
ABC_TYPE = 'DEF') and lookup_port like 'ABAC%'


Last edited by pludi; 03-09-2012 at 07:51 AM..
# 2  
Old 03-09-2012
Code:
/(where[\s\S]*)/i

# 3  
Old 03-09-2012
Code:
$1=~s/\n//;

# 4  
Old 03-09-2012
by default the "." does not match a new line, you can extend it to match across lines (ie, match newlines) with the s modifier. See code sample for practical examole of what I'm trying to say
Code:
skrynesaver@busybox~$ perl -e ' my $string="This is line one
this line two
and this is the end of the string";print "$1\n" if $string=~/is line(.*)/;'
 one
skrynesaver@busybox~$ perl -e ' my $string="This is line one
this line two
and this is the end of the string";print "$1\n" if $string=~/is line(.*)/s;'
 one
this line two
and this is the end of the string

As you can see the s modifier extended the characters matched by .* across multiple lines within the string
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

perl - Removing dots(".") from the data

Hi Friends, I have a file1 as below file1.txt 100000.||1925-01-10|00:00|1862SHERMA NAVE#1SE.||EVTON|IL|60201||22509.|BDSS|62007|2639.|26670 100001.||1935-01-10|00:00|1862NEW . YRK NO.||EVTON|IL|60201||22509.|BDSS|62007|2639.|26670. 100002.||1965-01-10|00:00|1862 IND . INC,CL... (6 Replies)
Discussion started by: i150371485
6 Replies

3. Shell Programming and Scripting

Deleting a row based on fetched value of column

Hi, I have a file which consists of two columns but the first one can be varying in length like 123456789 0abcd 123456789 0abcd 4015 0 0abcd 5000 0abcd I want to go through the file reading each line, count the number of characters in the first column and delete... (2 Replies)
Discussion started by: swasid
2 Replies

4. Shell Programming and Scripting

Removing data with pattern matching

I have the following: HH:MM:SS I want to use either % or # sign to remove :SS can somebody please provide me an example. I know how to do this in awk, but awk is too much overhead for something this simple since I will be doing this in a loop a lot of times. Thanks in advance to all... (2 Replies)
Discussion started by: BeefStu
2 Replies

5. Shell Programming and Scripting

SFTP to server, pulling data and removing the data

Hi all, I have the following script, but are not too sure about the syntax to complete the script. In essence, the script must connect to a SFTP server at a client site with username and password located in a file on my server. Then change to the appropriate directory. Pull the data to the... (1 Reply)
Discussion started by: codenjanod
1 Replies

6. UNIX for Advanced & Expert Users

Issues while sending a mail having records fetched from SQL -all in UNIX

hi-I want to write a UNIX Script which will fetch records from Oracle database.I want to store these records in a file under fields like email address,name and the transaction_id and then fetch these records from the file and send the email to individual users with their transaction ID details. (4 Replies)
Discussion started by: DeepSalwan
4 Replies

7. Shell Programming and Scripting

Data fetched from text file and save in a csv file

Hi i have wriiten a script which fetches the data from text file, and saves in the output in a text file itself, but i want that the output should save in different columns. I have the output like: For Channel:response_time__24.txt 1547 data points 0.339 0.299 0.448 0.581 7.380 ... (1 Reply)
Discussion started by: rohitkalia
1 Replies

8. Shell Programming and Scripting

Removing spaces from data

Hi, I want to remove spaces from data. Data is: 1,aa ,21, 22 2,a a ,23 ,24 3, ,25 ,26 output should be: 1,aa,21,22 2,a a,23,24 3, ,25,26 i.e i have to remove leading and trailing spaces.Not the space between data and also i dont want to remove the space if data is... (4 Replies)
Discussion started by: monika
4 Replies

9. Shell Programming and Scripting

Variable value not being fetched in the filename..

Hi, In the code below, the $DD1, $DD2, $MM1, $MM2 are not fetching the values. Can anybody tell me where have i made wrong. Shift_date.sh is a script which gives the previous date if we give the current date in the format YYYYMMDD and +/- how many days past/future.. Like Shift_date.sh... (3 Replies)
Discussion started by: RRVARMA
3 Replies

10. Shell Programming and Scripting

Removing Null data in output

Hello all, I have a script that has an infile with system package information. For the most part the script is looking well. The only thing i need help is in testing for null entries and removing null data. #!/usr/bin/ksh for i in `cat /mwncps/bin/eco_pack` do NAME=`pkginfo -l |... (2 Replies)
Discussion started by: liketheshell
2 Replies
Login or Register to Ask a Question