Syntax error: Unterminated quoted string. Cannot find error












0















I'm writing a script to parse a larger file into usable data. I will attach the script below. The script was not running as I wanted and I thought it might have been the if/then statement I used, but when I took that off it revealed the real problem. This is now the error I am getting which makes it seem like the real problem is a quote mark of some kind.



FirstName,LastName,Company,Address,City,County,State,ZIP,Phone,Fax,Email,Web
FinalProject.sh: 36: FinalProject.sh: Syntax error: Unterminated quoted string


While I technically understand what the syntax error means, I cannot find where the problem is, and I have been trying to fix it for about half an hour. Help would be greatly appreciated!



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
for LINE in 'grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11)","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}''
do
FNAME='echo ${LINE} | awk -F, '{print $1}''
LNAME='echo ${LINE} | awk -F, '{print $2}''
COMPANY='echo ${LINE} | awk -F, '{print $3}''
ADDRESS='echo ${LINE} | awk -F, '{print $4}''
CITY='echo ${LINE} | awk -F, '{print $5}''
COUNTY='echo ${LINE} | awk -F, '{print $6}''
STATE='echo ${LINE} | awk -F, '{print $7}''
ZIP='echo ${LINE} | awk -F, '{print $8}''
PHONE='echo ${LINE} | awk -F, '{print $9}''
FAX='echo ${LINE} | awk -F, '{print $10}''
EMAIL='echo ${LINE} | awk -F, '{print $11}''
WEB='echo ${LINE} | awk -F, '{print $12}''
done









share|improve this question
















bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    I think you need to review your syntax for command substitution

    – steeldriver
    Dec 13 '15 at 1:10











  • the grep pipeline should be in back quotes not single quotes, as should each of the echo pipelines in the body of the loop

    – Murray Jensen
    Dec 13 '15 at 1:13
















0















I'm writing a script to parse a larger file into usable data. I will attach the script below. The script was not running as I wanted and I thought it might have been the if/then statement I used, but when I took that off it revealed the real problem. This is now the error I am getting which makes it seem like the real problem is a quote mark of some kind.



FirstName,LastName,Company,Address,City,County,State,ZIP,Phone,Fax,Email,Web
FinalProject.sh: 36: FinalProject.sh: Syntax error: Unterminated quoted string


While I technically understand what the syntax error means, I cannot find where the problem is, and I have been trying to fix it for about half an hour. Help would be greatly appreciated!



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
for LINE in 'grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11)","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}''
do
FNAME='echo ${LINE} | awk -F, '{print $1}''
LNAME='echo ${LINE} | awk -F, '{print $2}''
COMPANY='echo ${LINE} | awk -F, '{print $3}''
ADDRESS='echo ${LINE} | awk -F, '{print $4}''
CITY='echo ${LINE} | awk -F, '{print $5}''
COUNTY='echo ${LINE} | awk -F, '{print $6}''
STATE='echo ${LINE} | awk -F, '{print $7}''
ZIP='echo ${LINE} | awk -F, '{print $8}''
PHONE='echo ${LINE} | awk -F, '{print $9}''
FAX='echo ${LINE} | awk -F, '{print $10}''
EMAIL='echo ${LINE} | awk -F, '{print $11}''
WEB='echo ${LINE} | awk -F, '{print $12}''
done









share|improve this question
















bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    I think you need to review your syntax for command substitution

    – steeldriver
    Dec 13 '15 at 1:10











  • the grep pipeline should be in back quotes not single quotes, as should each of the echo pipelines in the body of the loop

    – Murray Jensen
    Dec 13 '15 at 1:13














0












0








0








I'm writing a script to parse a larger file into usable data. I will attach the script below. The script was not running as I wanted and I thought it might have been the if/then statement I used, but when I took that off it revealed the real problem. This is now the error I am getting which makes it seem like the real problem is a quote mark of some kind.



FirstName,LastName,Company,Address,City,County,State,ZIP,Phone,Fax,Email,Web
FinalProject.sh: 36: FinalProject.sh: Syntax error: Unterminated quoted string


While I technically understand what the syntax error means, I cannot find where the problem is, and I have been trying to fix it for about half an hour. Help would be greatly appreciated!



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
for LINE in 'grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11)","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}''
do
FNAME='echo ${LINE} | awk -F, '{print $1}''
LNAME='echo ${LINE} | awk -F, '{print $2}''
COMPANY='echo ${LINE} | awk -F, '{print $3}''
ADDRESS='echo ${LINE} | awk -F, '{print $4}''
CITY='echo ${LINE} | awk -F, '{print $5}''
COUNTY='echo ${LINE} | awk -F, '{print $6}''
STATE='echo ${LINE} | awk -F, '{print $7}''
ZIP='echo ${LINE} | awk -F, '{print $8}''
PHONE='echo ${LINE} | awk -F, '{print $9}''
FAX='echo ${LINE} | awk -F, '{print $10}''
EMAIL='echo ${LINE} | awk -F, '{print $11}''
WEB='echo ${LINE} | awk -F, '{print $12}''
done









share|improve this question
















I'm writing a script to parse a larger file into usable data. I will attach the script below. The script was not running as I wanted and I thought it might have been the if/then statement I used, but when I took that off it revealed the real problem. This is now the error I am getting which makes it seem like the real problem is a quote mark of some kind.



FirstName,LastName,Company,Address,City,County,State,ZIP,Phone,Fax,Email,Web
FinalProject.sh: 36: FinalProject.sh: Syntax error: Unterminated quoted string


While I technically understand what the syntax error means, I cannot find where the problem is, and I have been trying to fix it for about half an hour. Help would be greatly appreciated!



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
for LINE in 'grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11)","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}''
do
FNAME='echo ${LINE} | awk -F, '{print $1}''
LNAME='echo ${LINE} | awk -F, '{print $2}''
COMPANY='echo ${LINE} | awk -F, '{print $3}''
ADDRESS='echo ${LINE} | awk -F, '{print $4}''
CITY='echo ${LINE} | awk -F, '{print $5}''
COUNTY='echo ${LINE} | awk -F, '{print $6}''
STATE='echo ${LINE} | awk -F, '{print $7}''
ZIP='echo ${LINE} | awk -F, '{print $8}''
PHONE='echo ${LINE} | awk -F, '{print $9}''
FAX='echo ${LINE} | awk -F, '{print $10}''
EMAIL='echo ${LINE} | awk -F, '{print $11}''
WEB='echo ${LINE} | awk -F, '{print $12}''
done






bash shell-script debugging






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 13 '15 at 0:18









slm

253k71535687




253k71535687










asked Dec 13 '15 at 0:15









law10law10

1




1





bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    I think you need to review your syntax for command substitution

    – steeldriver
    Dec 13 '15 at 1:10











  • the grep pipeline should be in back quotes not single quotes, as should each of the echo pipelines in the body of the loop

    – Murray Jensen
    Dec 13 '15 at 1:13














  • 1





    I think you need to review your syntax for command substitution

    – steeldriver
    Dec 13 '15 at 1:10











  • the grep pipeline should be in back quotes not single quotes, as should each of the echo pipelines in the body of the loop

    – Murray Jensen
    Dec 13 '15 at 1:13








1




1





I think you need to review your syntax for command substitution

– steeldriver
Dec 13 '15 at 1:10





I think you need to review your syntax for command substitution

– steeldriver
Dec 13 '15 at 1:10













the grep pipeline should be in back quotes not single quotes, as should each of the echo pipelines in the body of the loop

– Murray Jensen
Dec 13 '15 at 1:13





the grep pipeline should be in back quotes not single quotes, as should each of the echo pipelines in the body of the loop

– Murray Jensen
Dec 13 '15 at 1:13










1 Answer
1






active

oldest

votes


















0














In general, you are using single quotes '...' to wrap "command execution", which should be wrapped with back-quotes `...`, or (much better) $(...).



That makes the line that start with: for LINE in 'grep and ends with
}'' fail.

Making the minimum possible changes, the code becomes:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
for LINE in `grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'`
do
FNAME=`echo ${LINE} | awk -F, '{print $1}'`
LNAME=`echo ${LINE} | awk -F, '{print $2}'`
COMPANY=`echo ${LINE} | awk -F, '{print $3}'`
ADDRESS=`echo ${LINE} | awk -F, '{print $4}'`
CITY=`echo ${LINE} | awk -F, '{print $5}'`
COUNTY=`echo ${LINE} | awk -F, '{print $6}'`
STATE=`echo ${LINE} | awk -F, '{print $7}'`
ZIP=`echo ${LINE} | awk -F, '{print $8}'`
PHONE=`echo ${LINE} | awk -F, '{print $9}'`
FAX=`echo ${LINE} | awk -F, '{print $10}'`
EMAIL=`echo ${LINE} | awk -F, '{print $11}'`
WEB=`echo ${LINE} | awk -F, '{print $12}'`
done




However, it is a mistake to try to process a file with a for loop, you should use read to get the output of grep:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
while IFS=$'n' read -r LINE
do
FNAME="$(echo ${LINE} | awk -F, '{print $1}')"
LNAME="$(echo ${LINE} | awk -F, '{print $2}')"
COMPANY="$(echo ${LINE} | awk -F, '{print $3}')"
ADDRESS="$(echo ${LINE} | awk -F, '{print $4}')"
CITY="$(echo ${LINE} | awk -F, '{print $5}')"
COUNTY="$(echo ${LINE} | awk -F, '{print $6}')"
STATE="$(echo ${LINE} | awk -F, '{print $7}')"
ZIP="$(echo ${LINE} | awk -F, '{print $8}')"
PHONE="$(echo ${LINE} | awk -F, '{print $9}')"
FAX="$(echo ${LINE} | awk -F, '{print $10}')"
EMAIL="$(echo ${LINE} | awk -F, '{print $11}')"
WEB="$(echo ${LINE} | awk -F, '{print $12}')"
done < <(
grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'
)





share|improve this answer


























  • why is $() "much better" than back quotes?

    – Murray Jensen
    Dec 13 '15 at 1:15











  • @MurrayJensen Because it becomes very clear where a "Command Execution starts and ends.

    – user79743
    Dec 13 '15 at 1:22











  • I think it confuses things between variable expansions and command substitutions ... back quotes is very clear IMO

    – Murray Jensen
    Dec 13 '15 at 1:28











  • @MurrayJensen Exparience has shown that backticks are more dificult to use:The second form COMMAND` is more or less obsolete for Bash, since it has some trouble with nesting ("inner" backticks need to be escaped) and escaping characters. Use $(COMMAND), it's also POSIX! `

    – user79743
    Dec 13 '15 at 1:37











  • echo ${LINE} | awk {print $n}'` squashes any consecutive whitespace and can delete some leading tokens from the first field. Assuming you actually want all fields as-is, it's much simpler (and faster) to just do while IFS=, read -r FNAME LNAME COMPANY etc etc. Or if all input lines contain at least 12 fields, skip the awk to select NF-11 etc, use read -r LINE; IFS=,; set -- $LINE; shift $#-12 then just use FNAME=$1; LNAME=$2; etc.

    – dave_thompson_085
    Dec 15 '15 at 6:35













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f249005%2fsyntax-error-unterminated-quoted-string-cannot-find-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














In general, you are using single quotes '...' to wrap "command execution", which should be wrapped with back-quotes `...`, or (much better) $(...).



That makes the line that start with: for LINE in 'grep and ends with
}'' fail.

Making the minimum possible changes, the code becomes:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
for LINE in `grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'`
do
FNAME=`echo ${LINE} | awk -F, '{print $1}'`
LNAME=`echo ${LINE} | awk -F, '{print $2}'`
COMPANY=`echo ${LINE} | awk -F, '{print $3}'`
ADDRESS=`echo ${LINE} | awk -F, '{print $4}'`
CITY=`echo ${LINE} | awk -F, '{print $5}'`
COUNTY=`echo ${LINE} | awk -F, '{print $6}'`
STATE=`echo ${LINE} | awk -F, '{print $7}'`
ZIP=`echo ${LINE} | awk -F, '{print $8}'`
PHONE=`echo ${LINE} | awk -F, '{print $9}'`
FAX=`echo ${LINE} | awk -F, '{print $10}'`
EMAIL=`echo ${LINE} | awk -F, '{print $11}'`
WEB=`echo ${LINE} | awk -F, '{print $12}'`
done




However, it is a mistake to try to process a file with a for loop, you should use read to get the output of grep:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
while IFS=$'n' read -r LINE
do
FNAME="$(echo ${LINE} | awk -F, '{print $1}')"
LNAME="$(echo ${LINE} | awk -F, '{print $2}')"
COMPANY="$(echo ${LINE} | awk -F, '{print $3}')"
ADDRESS="$(echo ${LINE} | awk -F, '{print $4}')"
CITY="$(echo ${LINE} | awk -F, '{print $5}')"
COUNTY="$(echo ${LINE} | awk -F, '{print $6}')"
STATE="$(echo ${LINE} | awk -F, '{print $7}')"
ZIP="$(echo ${LINE} | awk -F, '{print $8}')"
PHONE="$(echo ${LINE} | awk -F, '{print $9}')"
FAX="$(echo ${LINE} | awk -F, '{print $10}')"
EMAIL="$(echo ${LINE} | awk -F, '{print $11}')"
WEB="$(echo ${LINE} | awk -F, '{print $12}')"
done < <(
grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'
)





share|improve this answer


























  • why is $() "much better" than back quotes?

    – Murray Jensen
    Dec 13 '15 at 1:15











  • @MurrayJensen Because it becomes very clear where a "Command Execution starts and ends.

    – user79743
    Dec 13 '15 at 1:22











  • I think it confuses things between variable expansions and command substitutions ... back quotes is very clear IMO

    – Murray Jensen
    Dec 13 '15 at 1:28











  • @MurrayJensen Exparience has shown that backticks are more dificult to use:The second form COMMAND` is more or less obsolete for Bash, since it has some trouble with nesting ("inner" backticks need to be escaped) and escaping characters. Use $(COMMAND), it's also POSIX! `

    – user79743
    Dec 13 '15 at 1:37











  • echo ${LINE} | awk {print $n}'` squashes any consecutive whitespace and can delete some leading tokens from the first field. Assuming you actually want all fields as-is, it's much simpler (and faster) to just do while IFS=, read -r FNAME LNAME COMPANY etc etc. Or if all input lines contain at least 12 fields, skip the awk to select NF-11 etc, use read -r LINE; IFS=,; set -- $LINE; shift $#-12 then just use FNAME=$1; LNAME=$2; etc.

    – dave_thompson_085
    Dec 15 '15 at 6:35


















0














In general, you are using single quotes '...' to wrap "command execution", which should be wrapped with back-quotes `...`, or (much better) $(...).



That makes the line that start with: for LINE in 'grep and ends with
}'' fail.

Making the minimum possible changes, the code becomes:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
for LINE in `grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'`
do
FNAME=`echo ${LINE} | awk -F, '{print $1}'`
LNAME=`echo ${LINE} | awk -F, '{print $2}'`
COMPANY=`echo ${LINE} | awk -F, '{print $3}'`
ADDRESS=`echo ${LINE} | awk -F, '{print $4}'`
CITY=`echo ${LINE} | awk -F, '{print $5}'`
COUNTY=`echo ${LINE} | awk -F, '{print $6}'`
STATE=`echo ${LINE} | awk -F, '{print $7}'`
ZIP=`echo ${LINE} | awk -F, '{print $8}'`
PHONE=`echo ${LINE} | awk -F, '{print $9}'`
FAX=`echo ${LINE} | awk -F, '{print $10}'`
EMAIL=`echo ${LINE} | awk -F, '{print $11}'`
WEB=`echo ${LINE} | awk -F, '{print $12}'`
done




However, it is a mistake to try to process a file with a for loop, you should use read to get the output of grep:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
while IFS=$'n' read -r LINE
do
FNAME="$(echo ${LINE} | awk -F, '{print $1}')"
LNAME="$(echo ${LINE} | awk -F, '{print $2}')"
COMPANY="$(echo ${LINE} | awk -F, '{print $3}')"
ADDRESS="$(echo ${LINE} | awk -F, '{print $4}')"
CITY="$(echo ${LINE} | awk -F, '{print $5}')"
COUNTY="$(echo ${LINE} | awk -F, '{print $6}')"
STATE="$(echo ${LINE} | awk -F, '{print $7}')"
ZIP="$(echo ${LINE} | awk -F, '{print $8}')"
PHONE="$(echo ${LINE} | awk -F, '{print $9}')"
FAX="$(echo ${LINE} | awk -F, '{print $10}')"
EMAIL="$(echo ${LINE} | awk -F, '{print $11}')"
WEB="$(echo ${LINE} | awk -F, '{print $12}')"
done < <(
grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'
)





share|improve this answer


























  • why is $() "much better" than back quotes?

    – Murray Jensen
    Dec 13 '15 at 1:15











  • @MurrayJensen Because it becomes very clear where a "Command Execution starts and ends.

    – user79743
    Dec 13 '15 at 1:22











  • I think it confuses things between variable expansions and command substitutions ... back quotes is very clear IMO

    – Murray Jensen
    Dec 13 '15 at 1:28











  • @MurrayJensen Exparience has shown that backticks are more dificult to use:The second form COMMAND` is more or less obsolete for Bash, since it has some trouble with nesting ("inner" backticks need to be escaped) and escaping characters. Use $(COMMAND), it's also POSIX! `

    – user79743
    Dec 13 '15 at 1:37











  • echo ${LINE} | awk {print $n}'` squashes any consecutive whitespace and can delete some leading tokens from the first field. Assuming you actually want all fields as-is, it's much simpler (and faster) to just do while IFS=, read -r FNAME LNAME COMPANY etc etc. Or if all input lines contain at least 12 fields, skip the awk to select NF-11 etc, use read -r LINE; IFS=,; set -- $LINE; shift $#-12 then just use FNAME=$1; LNAME=$2; etc.

    – dave_thompson_085
    Dec 15 '15 at 6:35
















0












0








0







In general, you are using single quotes '...' to wrap "command execution", which should be wrapped with back-quotes `...`, or (much better) $(...).



That makes the line that start with: for LINE in 'grep and ends with
}'' fail.

Making the minimum possible changes, the code becomes:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
for LINE in `grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'`
do
FNAME=`echo ${LINE} | awk -F, '{print $1}'`
LNAME=`echo ${LINE} | awk -F, '{print $2}'`
COMPANY=`echo ${LINE} | awk -F, '{print $3}'`
ADDRESS=`echo ${LINE} | awk -F, '{print $4}'`
CITY=`echo ${LINE} | awk -F, '{print $5}'`
COUNTY=`echo ${LINE} | awk -F, '{print $6}'`
STATE=`echo ${LINE} | awk -F, '{print $7}'`
ZIP=`echo ${LINE} | awk -F, '{print $8}'`
PHONE=`echo ${LINE} | awk -F, '{print $9}'`
FAX=`echo ${LINE} | awk -F, '{print $10}'`
EMAIL=`echo ${LINE} | awk -F, '{print $11}'`
WEB=`echo ${LINE} | awk -F, '{print $12}'`
done




However, it is a mistake to try to process a file with a for loop, you should use read to get the output of grep:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
while IFS=$'n' read -r LINE
do
FNAME="$(echo ${LINE} | awk -F, '{print $1}')"
LNAME="$(echo ${LINE} | awk -F, '{print $2}')"
COMPANY="$(echo ${LINE} | awk -F, '{print $3}')"
ADDRESS="$(echo ${LINE} | awk -F, '{print $4}')"
CITY="$(echo ${LINE} | awk -F, '{print $5}')"
COUNTY="$(echo ${LINE} | awk -F, '{print $6}')"
STATE="$(echo ${LINE} | awk -F, '{print $7}')"
ZIP="$(echo ${LINE} | awk -F, '{print $8}')"
PHONE="$(echo ${LINE} | awk -F, '{print $9}')"
FAX="$(echo ${LINE} | awk -F, '{print $10}')"
EMAIL="$(echo ${LINE} | awk -F, '{print $11}')"
WEB="$(echo ${LINE} | awk -F, '{print $12}')"
done < <(
grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'
)





share|improve this answer















In general, you are using single quotes '...' to wrap "command execution", which should be wrapped with back-quotes `...`, or (much better) $(...).



That makes the line that start with: for LINE in 'grep and ends with
}'' fail.

Making the minimum possible changes, the code becomes:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
for LINE in `grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'`
do
FNAME=`echo ${LINE} | awk -F, '{print $1}'`
LNAME=`echo ${LINE} | awk -F, '{print $2}'`
COMPANY=`echo ${LINE} | awk -F, '{print $3}'`
ADDRESS=`echo ${LINE} | awk -F, '{print $4}'`
CITY=`echo ${LINE} | awk -F, '{print $5}'`
COUNTY=`echo ${LINE} | awk -F, '{print $6}'`
STATE=`echo ${LINE} | awk -F, '{print $7}'`
ZIP=`echo ${LINE} | awk -F, '{print $8}'`
PHONE=`echo ${LINE} | awk -F, '{print $9}'`
FAX=`echo ${LINE} | awk -F, '{print $10}'`
EMAIL=`echo ${LINE} | awk -F, '{print $11}'`
WEB=`echo ${LINE} | awk -F, '{print $12}'`
done




However, it is a mistake to try to process a file with a for loop, you should use read to get the output of grep:



#!/bin/bash

OLDIFS=${IFS}
IFS=$'n'

head -1 50000_a.csv | sed 's/"//g'
while IFS=$'n' read -r LINE
do
FNAME="$(echo ${LINE} | awk -F, '{print $1}')"
LNAME="$(echo ${LINE} | awk -F, '{print $2}')"
COMPANY="$(echo ${LINE} | awk -F, '{print $3}')"
ADDRESS="$(echo ${LINE} | awk -F, '{print $4}')"
CITY="$(echo ${LINE} | awk -F, '{print $5}')"
COUNTY="$(echo ${LINE} | awk -F, '{print $6}')"
STATE="$(echo ${LINE} | awk -F, '{print $7}')"
ZIP="$(echo ${LINE} | awk -F, '{print $8}')"
PHONE="$(echo ${LINE} | awk -F, '{print $9}')"
FAX="$(echo ${LINE} | awk -F, '{print $10}')"
EMAIL="$(echo ${LINE} | awk -F, '{print $11}')"
WEB="$(echo ${LINE} | awk -F, '{print $12}')"
done < <(
grep WV 50000_a.csv | sed 's/"//g' | awk -F, '{print $(NF-11) ","
$(NF-10)","
$(NF-9)","
$(NF-8)","
$(NF-7)","
$(NF-6)","
$(NF-5)","
$(NF-4)","
$(NF-3)","
$(NF-2)","
$(NF-1)","
$NF
}'
)






share|improve this answer














share|improve this answer



share|improve this answer








edited May 23 '17 at 12:39









Community

1




1










answered Dec 13 '15 at 1:13







user79743




















  • why is $() "much better" than back quotes?

    – Murray Jensen
    Dec 13 '15 at 1:15











  • @MurrayJensen Because it becomes very clear where a "Command Execution starts and ends.

    – user79743
    Dec 13 '15 at 1:22











  • I think it confuses things between variable expansions and command substitutions ... back quotes is very clear IMO

    – Murray Jensen
    Dec 13 '15 at 1:28











  • @MurrayJensen Exparience has shown that backticks are more dificult to use:The second form COMMAND` is more or less obsolete for Bash, since it has some trouble with nesting ("inner" backticks need to be escaped) and escaping characters. Use $(COMMAND), it's also POSIX! `

    – user79743
    Dec 13 '15 at 1:37











  • echo ${LINE} | awk {print $n}'` squashes any consecutive whitespace and can delete some leading tokens from the first field. Assuming you actually want all fields as-is, it's much simpler (and faster) to just do while IFS=, read -r FNAME LNAME COMPANY etc etc. Or if all input lines contain at least 12 fields, skip the awk to select NF-11 etc, use read -r LINE; IFS=,; set -- $LINE; shift $#-12 then just use FNAME=$1; LNAME=$2; etc.

    – dave_thompson_085
    Dec 15 '15 at 6:35





















  • why is $() "much better" than back quotes?

    – Murray Jensen
    Dec 13 '15 at 1:15











  • @MurrayJensen Because it becomes very clear where a "Command Execution starts and ends.

    – user79743
    Dec 13 '15 at 1:22











  • I think it confuses things between variable expansions and command substitutions ... back quotes is very clear IMO

    – Murray Jensen
    Dec 13 '15 at 1:28











  • @MurrayJensen Exparience has shown that backticks are more dificult to use:The second form COMMAND` is more or less obsolete for Bash, since it has some trouble with nesting ("inner" backticks need to be escaped) and escaping characters. Use $(COMMAND), it's also POSIX! `

    – user79743
    Dec 13 '15 at 1:37











  • echo ${LINE} | awk {print $n}'` squashes any consecutive whitespace and can delete some leading tokens from the first field. Assuming you actually want all fields as-is, it's much simpler (and faster) to just do while IFS=, read -r FNAME LNAME COMPANY etc etc. Or if all input lines contain at least 12 fields, skip the awk to select NF-11 etc, use read -r LINE; IFS=,; set -- $LINE; shift $#-12 then just use FNAME=$1; LNAME=$2; etc.

    – dave_thompson_085
    Dec 15 '15 at 6:35



















why is $() "much better" than back quotes?

– Murray Jensen
Dec 13 '15 at 1:15





why is $() "much better" than back quotes?

– Murray Jensen
Dec 13 '15 at 1:15













@MurrayJensen Because it becomes very clear where a "Command Execution starts and ends.

– user79743
Dec 13 '15 at 1:22





@MurrayJensen Because it becomes very clear where a "Command Execution starts and ends.

– user79743
Dec 13 '15 at 1:22













I think it confuses things between variable expansions and command substitutions ... back quotes is very clear IMO

– Murray Jensen
Dec 13 '15 at 1:28





I think it confuses things between variable expansions and command substitutions ... back quotes is very clear IMO

– Murray Jensen
Dec 13 '15 at 1:28













@MurrayJensen Exparience has shown that backticks are more dificult to use:The second form COMMAND` is more or less obsolete for Bash, since it has some trouble with nesting ("inner" backticks need to be escaped) and escaping characters. Use $(COMMAND), it's also POSIX! `

– user79743
Dec 13 '15 at 1:37





@MurrayJensen Exparience has shown that backticks are more dificult to use:The second form COMMAND` is more or less obsolete for Bash, since it has some trouble with nesting ("inner" backticks need to be escaped) and escaping characters. Use $(COMMAND), it's also POSIX! `

– user79743
Dec 13 '15 at 1:37













echo ${LINE} | awk {print $n}'` squashes any consecutive whitespace and can delete some leading tokens from the first field. Assuming you actually want all fields as-is, it's much simpler (and faster) to just do while IFS=, read -r FNAME LNAME COMPANY etc etc. Or if all input lines contain at least 12 fields, skip the awk to select NF-11 etc, use read -r LINE; IFS=,; set -- $LINE; shift $#-12 then just use FNAME=$1; LNAME=$2; etc.

– dave_thompson_085
Dec 15 '15 at 6:35







echo ${LINE} | awk {print $n}'` squashes any consecutive whitespace and can delete some leading tokens from the first field. Assuming you actually want all fields as-is, it's much simpler (and faster) to just do while IFS=, read -r FNAME LNAME COMPANY etc etc. Or if all input lines contain at least 12 fields, skip the awk to select NF-11 etc, use read -r LINE; IFS=,; set -- $LINE; shift $#-12 then just use FNAME=$1; LNAME=$2; etc.

– dave_thompson_085
Dec 15 '15 at 6:35




















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f249005%2fsyntax-error-unterminated-quoted-string-cannot-find-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Loup dans la culture

How to solve the problem of ntp “Unable to contact time server” from KDE?

ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux