473,383 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Please help with AWK

1
I need a AWK script do generate multiple INSERT statement for MySQL. Following is the example of the INSERT statement;

INSERT INTO `profile_setup` (`user_id`, `profile_name`, `profile_number`, `profile_type`) VALUES
('155214222', 'User Defined Profile', 2, 'user_defined'),
('155214222', 'User Defined Profile', 3, 'user_defined'),
('155214222', 'User Defined Profile', 4, 'user_defined'),
('155214222', 'User Defined Profile', 5, 'user_defined'),
('155214222', 'User Defined Profile', 6, 'user_defined'),
('155214222', 'User Defined Profile', 7, 'user_defined'),
('155214222', 'User Defined Profile', 8, 'user_defined');


I have a text file with the just the couple hundreds of user_id(s), example as following;

2061975327
21029196016
23331984074
60319888854
12273996604
900119944710
180819545267
152648481288
186018001855
194145515163
207281876612
219666022218

Please help me with script that will generate the sql statement for all the user ids. The profile number starts with 2 and end at 8.

Thanks
Dec 4 '07 #1
2 1303
Expand|Select|Wrap|Line Numbers
  1. echo 'INSERT INTO `profile_setup` (`user_id`, `profile_name`, `profile_number`, `profile_type`)
  2. VALUES'
  3. awk '{for(i=2;i<=8;i++)
  4.         print p v $1 v", "v"User Defined Profile"v", "i", "v"user_defined"v p1","
  5. }' p="(" v="'" p1=")" filename
  6. }
Use nawk or /usr/xpg4/bin/awk on Solaris.
Dec 5 '07 #2
Just noticed you want separate statements,
so:

Expand|Select|Wrap|Line Numbers
  1. awk '{
  2.     print "INSERT INTO " a "profile_setup" a " " p a "user_id" a ", "a "profile_name" a ", " a "profile_number" a ", " a "profile_type" a p1 " VALUES";
  3.     for(i=2;i<=7;i++)
  4.             print p v $1 v ", " v "User Defined Profile" v ", " i ", " v "user_defined" v p1 ","
  5.     print p v $1 v ", " v "User Defined Profile" v ", 8, " v "user_defined" v p1 ";"
  6. }' a="\`" p="(" v="'" p1=")" filename
Dec 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my...
2
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
3
by: Mark Broadbent | last post by:
could somebody please recommend a good book to prepare for exam Exam 70-320*: Developing XML Web Services and Server Components with Microsoft Visual C# and the Microsoft .NET Framework . One that...
13
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.