Results 1 to 10 of 12
I am having the following problem when executing this script. It currently looks as follows:
Code:
awk -F, -v dt="$(date "+%Y-%m-%d")" '{ OFS=FS; print "abc", dt, $1 }' foo.csv > ...
- 06-27-2008 #1Linux User
- Join Date
- Dec 2004
- Posts
- 323
Correcting bash script
I am having the following problem when executing this script. It currently looks as follows:
The response is "Illegal variable name."Code:awk -F, -v dt="$(date "+%Y-%m-%d")" '{ OFS=FS; print "abc", dt, $1 }' foo.csv > foo.txt
The first few lines of the input file foo.csv look as follows:
so it is a list of codes of which the codes in the first column are needed only. Prepended with the code "abc" and the date, the resulting file foo.txt should hold the following data:Code:SG70,B3B0M92,ANN8132R7036,25-Jun-08 SG68,B3B2J97,ANN8132R6871,25-Jun-08 ST71,B2Q4T68,ANN8132N4540,25-Jun-08 SG67,B3B2J75,ANN8132R6798,24-Jun-08
How do I correct the code above and preferably still keep a one liner?Code:"abc",2008-06-25,SG70 "abc",2008-06-25,SG68 "abc",2008-06-25,ST71 "abc",2008-06-25,SG67
Thanks in advance
- 06-29-2008 #2Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Code:awk -F"," '{print "abc" ",'$(date +%Y-%m-%d)'," $1}' foo.csv >foo.txt
- 06-30-2008 #3Linux User
- Join Date
- Dec 2004
- Posts
- 323
Thank you for your response. But why does it continue to say "Illegal variable name"?
- 07-01-2008 #4
post the output please
Linux and me it's a love story
- 07-01-2008 #5Linux User
- Join Date
- Dec 2004
- Posts
- 323
The machine is called madrid, there is only one foo-file before and after issuing the command.Code:madrid# ls f* foo.csv madrid# awk -F"," '{print "abc" ",'$(date +%Y-%m-%d)'," $1}' foo.csv >foo.txt Illegal variable name. madrid#
- 07-01-2008 #6
this works flawlessly on my box.
i just copied the command from your post then ran it with a dummy file i created for the purpose . and the result was as expected.Linux and me it's a love story
- 07-01-2008 #7Linux User
- Join Date
- Dec 2004
- Posts
- 323
Thanks for your response. So a good strategy would be the gradual addition of more of the components to this script until the culprit is found or could this be a permissioning issue?
- 07-02-2008 #8
i would create a small bash script containing only the maybe-faulty part then run it with
this is the bash debug mode and you will see what is going wrongCode:bash -x script_name
Linux and me it's a love story
- 07-02-2008 #9Linux User
- Join Date
- Dec 2004
- Posts
- 323
Thanks, that seems to work, because I have the foo.txt file now as designed. Can you explain however what is happening here:
The script has been named foo.sh and chmodded to +x. What do those plusses mean? Is it a problem that the first line of foo.sh is not #!/bin/bash or #!/bin/sh?Code:madrid# bash -x foo.sh ++ date +%Y-%m-%d + awk -F, '{print "abc" ",2008-07-02," $1}' foo.csv
- 07-02-2008 #10
when you run it like
you dont need to put the shebang(#!) because bash reads the file and executes the instructions found.Code:bash -option foo.sh
as for the + they are output in debug modeLinux and me it's a love story


Reply With Quote