sed parse a lign into a new sql file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed parse a lign into a new sql file
# 1  
Old 08-10-2011
sed parse a lign into a new sql file

Hi everyone,

another question while using sed.
my sed statement should parse every line in a file and store all "i" variable item a a new file.

any wrong arguments here?

Thanks a million.

task_name => name,
object_type => 'TABLE',
attr1 => 'TestR3',
attr2 => '$i',

for i in 'cat TOP10.OUT'
echo $i
echo $j
sed s/$TTest/$i/ > tmp/$j.sql
cat && sed 's/$TTest/$i/' > tmp/$j.sql
j=`expr $j + 1 `

---------- Post updated at 02:23 PM ---------- Previous update was at 01:46 PM ----------

wrong arguments:
I've replaced the single quotes by " " but still doesn't work... apologies for being a nerde...

Last edited by pludi; 08-10-2011 at 05:39 PM..
# 2  
Old 08-10-2011
sed help

I am assuming you are having problems embedding shell variables in sed:

sed 's/$TTest/$i/'

Try this:

# untested
sed 's/'"$T"'Test/'"$i"'/'

A word of warning: the way you are reading the file with the for loop, you will have problems if file TOP10.OUT has more than one word per line.


Last edited by nails; 08-10-2011 at 09:19 PM..
This User Gave Thanks to nails For This Post:
# 3  
Old 08-10-2011
oups, indeed....
can i optimize?
# 4  
Old 08-10-2011
sed help

Consider using a while loop instead of the for:

# untested
while read i
    echo "$i"
done < TOP10.OUT

This User Gave Thanks to nails For This Post:
# 5  
Old 08-10-2011
will try right away... you're gorgeous (being a lady I can say it, don't run awaySmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Parse with SQL

I am trying to parse a string using SQL but am too new and still learning. I have text in a control or field 685 that is variable, but always the same format. field 685 input arr 2q33.3q34(200,900,700-209,000,000)x2 xxx Desired output 2:200900700-209000000 Basically, the # after the... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Parse SQL text and only format first SELECT statement.

Hi Forum. Need your expertise on the following question. I have the following file which I would like to parse, find first block of SELECT statment and concatenate all input fields as 1 field (~ delimited): Old File: SELECT /*+ USE_HASH(CCOMM ICAR IMAP IAS IP IMAS IMPS IAP SPCA) */ ... (5 Replies)
Discussion started by: pchang
5 Replies

3. Shell Programming and Scripting

sql dump file - how to get certain values using sed

Hi, I have a dumpfile.sql - ========Start of file================= CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysql` /*!40100 DEFAULT CHARACTER SET latin1 */; CREATE TABLE `test_table1` ( `id` int ) AUTO_INCREMENT=12 CREATE TABLE `test_table2` ( `id` int ) AUTO_INCREMENT=120... (5 Replies)
Discussion started by: ashokvpp
5 Replies

4. Shell Programming and Scripting

Sed to parse log file

Hi all, thanks for reading the post. I'm trying to parse hundreds of log files in a directory. One log file looks similar to below: Investigator : Jim_Foo Custodian : Jim_Foo-HDD1-FOO-1234 Export Path : N:\FOO-1234\Foo_Foo Compute MD5 : No File List Only: No Extensions Selected:... (4 Replies)
Discussion started by: chipperuga
4 Replies

5. Shell Programming and Scripting

script to parse text file into sql commands

Hello all, I tried searching for something similiar before posting but couldn't come up with anything that fit what I need. In Linux, I'm trying to parse through a number of files and take the info in them and put it into mysql. My file is a dump from an expect script: ---filename... (3 Replies)
Discussion started by: hamanjam
3 Replies

6. Shell Programming and Scripting

formating sql file using awk or sed

Hi, I have a file where I would like to add a prompt type object_name statement before every create commnad create or replace force view test_view_01 ( col1 col2 col3 ) as (select a,b,c from sometable ); create or replace view test_view_02 ( col4 col5 col6 ) as (5 Replies)
Discussion started by: jville
5 Replies

7. Shell Programming and Scripting

sed parse small xml file

I have a tmp.xml file like: <?xml version="1.0" encoding="UTF-8"?> <Response> <Ip></Ip> <Status>OK</Status> <CountryCode>PL</CountryCode> <CountryName>Poland</CountryName> <RegionCode>82</RegionCode> <RegionName>Pomorskie</RegionName> <City>Gdansk</City> ... (9 Replies)
Discussion started by: unclecameron
9 Replies

8. Shell Programming and Scripting

sed command to parse Apache config file

Hi there, am trying to parse an Apache 'server' config file. A snippet of the config file is shown below: ..... ProxyPassReverse /foo ..... ..... RewriteRule ^/(.*)$1 RewriteRule /redirect$1 ........ (7 Replies)
Discussion started by: jy2k7ca
7 Replies

9. Shell Programming and Scripting

SED + Regex + SQL Input file

Here's the problem... I have a mysqldump file and I need to put single quotes around the date/time timestamp. So for example I have a line like: INSERT INTO attachments VALUES (1,182,2004-08-06 09:24:04,'description'... and I need it to become INSERT INTO attachments VALUES... (10 Replies)
Discussion started by: primal
10 Replies

10. Shell Programming and Scripting

To parse through the file and print output using awk or sed script

suppose if u have a file like that Hen ABCCSGSGSGJJJJK 15 Cock ABCCSGGGSGIJJJL 15 * * * * * * : * * * . * * * : Hen CFCDFCSDFCDERTF 30 Cock CHCDFCSDHCDEGFI 30 * . * * * * * * * : * * :* : : . The output shud be where there is : and . It shud... (4 Replies)
Discussion started by: cdfd123
4 Replies
Login or Register to Ask a Question