Converting Batch Script to Shell Script
Hi
I have a batch script : FOR /f "eol=; tokens=1,2,3,4 delims=, " %%i in (var.txt) do ... command This reads the data file var.txt How do i covert it into shell script. Thanks Sandeep |
Put it in a file, make the first line:
Code:
#!/bin/bash |
Hi
i need to know how to convert FOR /f "eol=; tokens=1,2,3,4 delims=, " %%i in (var.txt) in a shell script. |
So what have you done so far?
|
Hi
for VARIABLE in var.txt do .. Commands.. done But i need to read the file var.taxt i.e nextyear 2012 thisyear 2011 i need to read each line of this file and use "nextyear" and 2012 as $1 and $2 in first loop. In second loop $1 and $2 must take thisyear and 2011. I am confused if the read function can do this. |
Hi
i tried using awk, but this doesn't seems to work .. #!/bin/bash awk ' BEGIN { FS = "|" } { essmsh set variable $1 $2 #my commands to update the variable for nextyra as 2013 here } ' var.txt |
Well you firstly need to decide on what you would like to use, ie either bash or awk can easily do what you want, but to use both for something so trivial is a waste.
awk by default will read a file line by line and divide the contents based on FS which by default is any contiguous white space bash on the other hand you would need to use a loop (suggest while) and then the read command to extract data a line at a time. Then it will depend on how well you know the data as to whether or not you read the line into a single variable to be dissected later or split based on the IFS value into multiple variables or lastly into an array Below are some links that may help: http://tldp.org/LDP/abs/html/ http://mywiki.wooledge.org/TitleIndex http://www.gnu.org/software/gawk/man...ode/index.html |
Quote:
|
Hi
I tried to assign the variable #!/bin/bash awk ' BEGIN { FS = "|" } { var1=$1 value1=$2 var2=$3 Value2=$4 } ' var.txt where var.txt looks like thisyear 2013 nextyear 2014 but i want to use only $1 and $2 and loop in for every line in the file. Any suggestions. can for loop be used with awk |
Quote:
|
You may wish to read my first post again ... there is a key part about awk that you are missing.
|
All times are GMT -5. The time now is 09:59 PM. |