Need help create a bash script to edit CSV File
i need to edit 4th field in the CSV file (i need to subtract 5 from whatever number is their in the fourth field, if the number is negative then replace it with 0)
The separator is , Please help |
Can you post some lines of the CSV file as example? What have you tried until now?
|
Online,World,20080819,0,1200M05,045468004016,N,,42,94,,,,,,N
Online,World,20080819,13,1200M055,045468004023,N,,42,94,,,,,,N Online,World,20080819,0,1200M06,045468004030,N,,42,94,,,,,,N Online,World,20080819,67,1200M065,045468004047,N,,42,94,,,,,,N i tried to use awk but i am not that familiar with it |
Using awk you can do something like this:
Code:
awk -F, ' |
is it possible to do it in Bash. i am not familiar on how to use awk.
Can i use awk in bash as a command and create a script? |
Quote:
Code:
#/bin/bash |
works like a charm
Thanks a lot |
You're welcome! :)
Here is a bash solution, too Code:
#!/bin/bash |
I used the awk script and ran it in the cron job. but when i run the cron job the output file shows 0bytes. When i run it manually it runs fine. Can someone help me resolve this problem. I changed the file rights and the directory rights and gave them both 777 permission. NEED HELP!!!
Thanks |
The crontab has a very limited environment, different from what you get upon login. The PATH is usually limited to /bin:/usr/bin, so that a good rule is to specify the absolute path of all the commands in the script. You can also look at the mail of the user owning the crontab to see if there is any error message. On most systems the cron daemon sends the standard output and the standard error to the user's mail, unless they are redirected to a file. Feel free to post the whole script and the crontab entry to let us take a look at what the problem is.
|
It worked out great. I put in full path in the script and worked like a charm.
Thanks a lot |
help
Quote:
awk -F, 'BEGIN{OFS="|"}{if ($4 < 5) $4 = 0; else $4 = $4 - 5; print}' /path/to/input/file > /path/to/output/file Please help |
Quote:
Code:
awk -F"|" 'BEGIN{OFS=","}{if ($4 < 5) $4 = 0; else $4 = $4 - 5; print}' /path/to/input/file > /path/to/output/file Code:
awk 'BEGIN{FS="|"; OFS=","}{if ($4 < 5) $4 = 0; else $4 = $4 - 5; print}' /path/to/input/file > /path/to/output/file |
Thanks
|
All times are GMT -5. The time now is 10:33 AM. |