Assume that I have a file like this:
[inp] // This is the file name
2
1 2 3
5 7 9
This would be read in C++ using this code:
main()
{
freopen("inp","r",stdin); // Redirect stdin to file, while open the file in read mode
int n; cin >> n; // A variable to get the numbers of lines. n = 2 in this case and the file cursor is after the first line
for (int i = 0; i < n; i++) // n-time loop
{
int a, b, c; // 3 numbers to save 3 values on each line
cin >> a >> b >> c; // Read the numbers from each line. The file cursor after each loop is at the end of a line
doSomething(a, b, c); // Do something with 3 read variables.
}
}
Which means in C++, we can control the file cursor. My code in bash:
inp="./inp" # file name
n=$(head -1 $inp) # Get numbers of line to read
for i in {1..$n}
do
echo * | head -1 $inp | awk '{print $1;}' < $inp
done
Instead of getting only 1 and 5 from each line, the output I get was 2 1 5 on 3 lines. So I would think that we can't control the file cursor in bash. Are there any solution to this?
You can also write a webserver in Assembly, but it's the wrong tool for the job. See the link from @Secespitus above.
– Wildcard Jun 18 '19 at 00:00