Hi,
I'm not sure if deleting one or more lines should also be done from this script.
The following will count the amount of lines in a file and adjust the number to that amount:
Code:
#!/bin/bash
linesInFile="`awk 'END{ print NR}' infile`"
sed -i '$s/[0-9][0-9]*$/'${linesInFile}'/' infile
Example run:
Quote:
$ cat infile
1|sdfsfsdf|somestuffs|nfkfkakf|0
1|sdfsfsdf|somestuffs|nfkfkakf|0
1|sdfsfsdf|somestuffs|4
$ ./testscript
$ cat infile
1|sdfsfsdf|somestuffs|nfkfkakf|0
1|sdfsfsdf|somestuffs|nfkfkakf|0
1|sdfsfsdf|somestuffs|3
|
The
linesInFile part fills a variable with the actual amount of lines present in a file.
The sed part replaces the number present with the actual amount.
Hope this helps.