Is it possible to first delete a line in a textfile and then insert a number on that row (replace the number)
for example:
Hello-1
1 <- change this row to 2.
Hello-2
Hi, I think before I can give you a decent answer, I would need to know a bit more info, for example whether you are always going to be changing the same line, or whether you plan on changing lines that meet a certain criteria. If the latter, what criteria would you be using?
Also, in the brief example you have given, you have replaced 1 with 2... is that all you would want to do? Increment a number within a text file? Or would the changes differ from case to case?
A little more to go on would be helpful.
Regards, LHLTech
IBM CS - AIX V4.3 System Support
Halfway through CATE exams!
all I want to do is to increase numbers in a file.
for example:
Hello <- always the same
1 <- the 2:nd row should be increased to 2, and then 3,,,
(I have the numbers in a variable)
Hello2 <- row 3. always the same
1 <-should be increased with 1
hello3 ""
5 <- should be increased with 1.
I know that I can increase the numbers with:
sed /s/1/2/ file
but this will change all the 1:s in the file to 2.
I am unpacking files that comes in and a want to automatically check if they meet a specific criteria.
== match the numbers in the file.
How to do this?
The program is working right now, but if numbers in the file are the same, all the numbers will increase.
I would do it something like this.. though it's perhaps a little more involved...
# usage
# myscript <input file>
infile=$1
tmpfile=t_$$.tmp
rm -f $tmpfile
linecount=1
while read line
do
case $linecount in
2|4|6)
let linecount=linecount+1
numvar=`echo $line`
let numvar=numvar+1
echo "$numvar" >> $tmpfile
;;
*) let linecount=linecount+1
echo "$line" >> $tmpfile
;;
esac
done < $infile
mv $tmpfile $infile
Maybe you can take something from that and use it in your own script.
Regards,
LHLTech
IBM Certified Specialist - AIX System Support
Halfway through CATE exams!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.