Now I want the code to read first the second row (10000 in this case) and append it as the first column of the results of the current code. Row 2 in the data files have values of 10000, 20000, 30000,...1790000,1800000. For example, if I read for row which starts with 4, I want the output to be
You haven't told us what operating system or shell you're using, and grep is not capable of joining text from different lines in a file. For that you need something more like awk . For example:
Although written and tested using a Korn shell, this will also work with any shell that meets basic POSIX shell requirements for parameter expansions and uses Bourne shell syntax.
If you want to try this on a Solaris/SunOS system, change awk in this script to /usr/xpg4/bin/awk or nawk .
Is it always the line starting with 4 as identifier when to join this line with the 2nd? Or is there any other kind of criteria which line to join with the 2nd?
BSD, Linux, and UNIX systems shells expect the script that they read to be text files consisting of zero or more lines each line of which is terminated by a <newline> character. At least the first line in your script is terminated by a <carriage-return><newline> character pair which is what one would expect in a DOS/Windows text file. The error message is telling you that your operating system can't find a file named /bin/bash<carriage-return> (where <carriage-return> is the ASCII <CR> carriage return character).
Please get rid of the <carriage-return> characters in your script, and try running it again.