Hi linux scripting gurus. I have a very simple script I need to make, but I just can’t figure out how to do it. Here’s the deal:
I need to know how I can make a script to take a file that looks something like this:
12345678
91234567
56789012
34751021
…
and turn it into a file that looks like this:
1 12345678 12345678 03
2 91234567 91234567 03
3 56789012 56789012 03
4 34751021 34751021 03
…
With a couple of stipulations. I need to be able to start the numbering at any arbitrary value, so it would be a variable I would pass the script when running it. I know how to handle variables, and so I know if my variable was $1, the numbering would just be something like
$1
$1+1
$1+2
$1+3
…
The other stipulation is that I don’t know how many lines are necessarily going to be in each file. So I need to get the line count first and probably store that as a variable and do a for loop. How do I get just a line count for a file to store as a variable? I’m hazy on the syntax on for loops in bash scripts though.
And perhaps most embarrassingly, I’m not sure of how to actually copy the text of each line and then append it so that I have two copies of the number like I need on each line.
And lastly, the 03 was just an example, but this would actually be a variable entered when running the script, so I need to tack on that at the end as well.
So, basically, here’s my pseudocode for what I think I need to do.
$1 = line_number
$2 = batch_number
linecount{filename} = line_count
for i=0; i<=line_count; i++
concatenate {line_number+i," ",line i of filename, " ", line i of filename, " ", batch_number} >> newfile
I hope that makes sense. If you need clarification on anything please let me know.