How to run sed command to get sed file and output sql file


Alex Weber

Updated question : http://pastebin.com/SrVC8PvW :

sed file - csv2sql.sed:

s|\([A-Z]*\),\([A-Z]*\),\([A-Za-z0-9’ ()\.\!-]*\),\([A-Za-z0-9’ ()\.\!-]*\),\([0-9]*\)|INSERT INTO `Schedule` (`ID`,`YEAR`,`NUMBER`,`TeamR1`,`TeamR2`, `TeamR3`, `TeamB1`, `TeamB2`, `TeamB3`) VALUES ('\1', '\2', '\3', '\4', '\5', '\6', '\7', '\8', '\9');|g

CSV file (part):

1,2015,0,57,3310,3676,624,3802,3481

Console error:

sed: file csv2sql.sed line 1: invalid reference \9 on `s` command's RHS

I have a SED file called csv2sql.sed which will take a CSV file and output it as SQL syntax. I want to run the script and have a new sql file called schedules.sql in the same folder .

How can I fix the error I'm getting?

Martin Drutsburg

Assuming your sed file is correct (I doubt it), then you would run

sed -f csv2sql.sed xxx.dat > schedules.sql

where xxx.dat is the file containing your csv data.

Schedules.sql will be created in your current working directory.

Related


How to run sed command to get sed file and output sql file

Alex Weber Updated question : http://pastebin.com/SrVC8PvW : sed file - csv2sql.sed: s|\([A-Z]*\),\([A-Z]*\),\([A-Za-z0-9’ ()\.\!-]*\),\([A-Za-z0-9’ ()\.\!-]*\),\([0-9]*\)|INSERT INTO `Schedule` (`ID`,`YEAR`,`NUMBER`,`TeamR1`,`TeamR2`, `TeamR3`, `TeamB1`, `Tea

How to redirect output to specific file in sed command?

Wanteng Some context: I'm trying to build a generic Makefile with automatic dependency generation (using GCC as described here , non-recursive, and can be used at any level of my project. To do this, the generated dependency file needs to have the following fo

sed the terminal into the .command file

Mr. Weber My script can delete the first 4 lines (if the extension) of every file in a folder .txt. I want to be able to put the file.command with this script in the same folder, so I can double click and execute it. So I made a file with this: #!/bin/bash fi

How to remove a pattern using sed command in a file?

Lionel I have a document and I want to remove all schemas so that only some information remains, the creator/creator of the document. I managed to replace the patterns with a single word "PATTERN" to remove them easily. How to remove this word? Here is the com

How to replace $value in file using sed command?

Ricky I am using the following command to replace some values in a file. But even though the command works fine, it doesn't replace it. sed -i 's|"TIBEMS:U1278:${Internal.Agent Name}"|"TIBEMS:U1278:${External.Agent Name}"|g' EMS_PRIMS01_7111_Monitor.hrb Inia

How to use sed command in batch file

sreekem bose I wrote a shell script with the following command: if [[ $(echo $FILE_NAME | awk -F"_" '{print $3}') == "IMAGE" ]]; then echo "in if of f_name" F_NAME=`echo $FILE_NAME | sed 's/IMAGE/UCM/'` echo $F_NAME else echo "in else of f_name"

How to replace words in a file using sed command

Oleg I have a text file: org.jitsi.videobridge.xmpp.user.shard-1.HOSTNAME=localhost org.jitsi.videobridge.xmpp.user.shard-1.DOMAIN=auth.jc.name.com org.jitsi.videobridge.xmpp.user.shard-1.USERNAME=name org.jitsi.videobridge.xmpp.user.shard-1.PASSWORD=Hfr*7462

Insert another sed command in a file using sed

tabs_over_spaces I'm trying to use sed to insert at the end of each line in a file using the sed command - sed -r 's/$/ | sed -r s\/abc\/xyz\/ /' filename.extension Next, I want to use single quotes around the inner sed. This will look like - sed -r 's/$/ | se

Insert another sed command in a file using sed

tabs_over_spaces I'm trying to use sed to insert at the end of each line in a file using the sed command - sed -r 's/$/ | sed -r s\/abc\/xyz\/ /' filename.extension Next, I want to use single quotes around the inner sed. This will look like - sed -r 's/$/ | se

How to pipe command output to sed

Ray Blanco My sed command has #UPDATE key in the config file. Can't get the content of variable $GETKEY Can anyone help me? # Get key from output of the website. GETKEY=`wget https://www.badips.com/get/key -qO - | awk {'print $9'} | cut -d ":" -f3 | cut -d

How to pipe command output to sed

Ray Blanco My sed command has #UPDATE key in the config file. Can't get the content of variable $GETKEY Can anyone help me? # Get key from output of the website. GETKEY=`wget https://www.badips.com/get/key -qO - | awk {'print $9'} | cut -d ":" -f3 | cut -d

Pass sed output like a file

Buffin I have ruby script that receives the name of the config file as a parameter. I need to run it with looping changes to certain parameters inside the config on each iteration. Everything works fine with sed, but I don't know how to pass sed's script outpu

sed how to get pattern from file

sgp667 I have two files, one holds a list of patterns and the other needs to make changes based on those patterns. So far I have been trying cat patterns.txt| xargs -n1| sed 's/patternfromfile/subtitution/' But I'm not sure how to enter xargs in 's/here //' t

sed how to get pattern from file

sgp667 I have two files, one holds a list of patterns and the other needs to make changes based on those patterns. So far I have been trying cat patterns.txt| xargs -n1| sed 's/patternfromfile/subtitution/' But I'm not sure how to enter xargs in 's/here //' t

How to replace strings in SQL file with sed

KodeFor.Me I have a multisite WordPress installation with multiple sites for a company I work for, and I've generated a bash script that pulls the database tables for each site individually. Additionally, we name each site based on the location of each replica

How to replace strings in SQL file with sed

KodeFor.Me I have a multisite WordPress installation with multiple sites for a company I work for, and I've generated a bash script that pulls the database tables for each site individually. Additionally, we name each site based on the location of each replica

sed command - replace strings in a file

Mercer I want to modify the value server.xmlin the file : <?xml version='1.0' encoding='utf-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for a

sed command - replace strings in a file

Mercer I want to modify the value server.xmlin the file : <?xml version='1.0' encoding='utf-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for a

How can I get the following output using the Sed command?

Ethan Quintaval My input is: "INTC_KEY,ABC1|OBJID,ABC2" I want to send the output to a file like this: DDS.INTC_KEY = REPL.OBJID AND DDS.ABC1 = REPL.ABC2 Here's what I've tried so far: sed 's/^/DDS./g' | sed 's/|/=REPL./g' | tr '\n' '~' | sed 's/~/_N~/g' | s

How can I get the following output using the Sed command?

Ethan Quintaval My input is: "INTC_KEY,ABC1|OBJID,ABC2" I want to send the output to a file like this: DDS.INTC_KEY = REPL.OBJID AND DDS.ABC1 = REPL.ABC2 Here's what I've tried so far: sed 's/^/DDS./g' | sed 's/|/=REPL./g' | tr '\n' '~' | sed 's/~/_N~/g' | s