simple awk/sed/tr question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple awk/sed/tr question
# 1  
Old 05-12-2009
simple awk/sed/tr question

I have a file
CREATE TABLE DDD_EXT --- 1000
(
val u1
val u1
);
CREATE TABLE dsdasd_EXT --- 1323
(
val u1
val u1
);
CREATE TABLE AAAAAA_EXT --- 1222
(
val u1
val u1
);
CREATE TABLE E_EXT --- 11
(
val u1
val u1
);
CREATE TABLE TRTERTRE_EXT --- 0
(
val u1
val u1
);
CREATE TABLE GRGY_EXT --- 0
(
val u1
val u1
);
CREATE TABLE RRRR_EXT --- 123
(
val u1
val u1
);

How can obtain the below output
insert into test_table values ( 'DDD' , NULL, 1000 );
insert into test_table values ( 'dsdasd, NULL, 1323);
insert into test_table values ( 'AAAAAA, NULL,1222 );
insert into test_table values ( 'E', NULL, 11);
insert into test_table values ( 'TRTERTRE, NULL, 0);
insert into test_table values ( 'GRGY, NULL, 0);
insert into test_table values ( 'RRRR, NULL, 123);
# 2  
Old 05-12-2009
awk /CREATE/{printf ("insert into test_table values('%s', NULL, %d)\n", $1, $3);} FILENAME
# 3  
Old 05-12-2009
Quote:
Originally Posted by JerryHone
awk /CREATE/{printf ("insert into test_table values('%s', NULL, %d)\n", $1, $3);} FILENAME
test your script.

@OP
Code:
awk  'BEGIN{FS="[ ]|_"}/CREATE/{printf ("insert into test_table values('%s', NULL, %d)\n", $3, $NF);}'  file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Simple SED Question

I don't understand this command behavior. echo "abc" |sed 's/a/&_&/' (4 Replies)
Discussion started by: Vartika18
4 Replies

2. Shell Programming and Scripting

awk help - Simple question

I have what a think is a simple question but I'm just a beginner in scripting. I'm my unix command line I run a date command that returns the following: Wed Apr 3 10:39:30 EDT 2013 How do I awk out the "10" only in awk? Or is awk the way to do it or is there a better way? (7 Replies)
Discussion started by: scj2012
7 Replies

3. Shell Programming and Scripting

Simple sed script question

Script newbie, so I'm sure I'm missing something obvious here, but how come this simple script does not work? #!/bin/bash ... (3 Replies)
Discussion started by: KidCactus
3 Replies

4. Shell Programming and Scripting

simple sed question - replace from phrase to end of line

I have the following line an in input file I want to digest with sed and simple replace the bold part with a variable defined in my bash script. I can do this in several sed operations but I know there must be a way to do it in a single sed line. What is the syntax? Line in file:... (1 Reply)
Discussion started by: graysky
1 Replies

5. Shell Programming and Scripting

Simple sed question.

I have a log output with a format similar to this: a=1, b= 2 c=0, d= 45, e=100 ... and so on. I figure I can just use awk or something to pipe the file to sed, but I'm trying to replace all the values above with 0. I've tried: cat blah | sed 's/=\(.*\),/0/'but that didn't work. ... (6 Replies)
Discussion started by: throw_a_stick
6 Replies

6. Shell Programming and Scripting

simple sed question

How do I remove parentheses using sed? input (192.168.1.1) output 192.168.1.1 (4 Replies)
Discussion started by: streetfighter2
4 Replies

7. UNIX for Dummies Questions & Answers

simple awk question

Hi , I have a simple question in awk, i have long string which i am getting for a grep command. the output contains 50 fields. I need to display like first 5 fileds in a line and rest of all fields in the next line. { for(i=5;i<NF;++i) s= $i; print $1,$2,$3,$4,$5,"\n",$s} Is the above... (1 Reply)
Discussion started by: senthilkumar_ak
1 Replies

8. Shell Programming and Scripting

simple sed question

hi is it possible to cut this two semicolon separated sed commands echo "string2 string3 string1" | sed s'/string1//g;s/string2//g' output: " string3 " to just one sed command without semicolon? thanks in advance funksen (10 Replies)
Discussion started by: funksen
10 Replies

9. Shell Programming and Scripting

sed - simple question

Hello My file looks like that => 12.56 have then 7888778.2566 what 44454.54545 878787.66565 if else 4445.54545455 I want to change all '.' on ',' . I'm trying to do it with sed but I don't know chow to build regular expression to change 454.4466 on 454,4466 ? (13 Replies)
Discussion started by: scotty_123
13 Replies

10. UNIX for Dummies Questions & Answers

Simple sed question

Is there an easier way to do the following: echo "|||||||" | sed 's/||/|0|/g; s/||/|0|/g' which would give the following |0|0|0|0|0|0| If it is not run twice it will not pick up the second occurance of the || and leave it empty as in echo "|||||||" | sed 's/||/|0|/g' which would give... (3 Replies)
Discussion started by: maverick
3 Replies
Login or Register to Ask a Question