Line manipulation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Line manipulation
# 1  
Old 12-08-2009
Line manipulation

hi guys,

I have wrote a code to essentially to scan line by line and extract the epoch time and count value. I was able to compare the line time with current time and make an if condition statement to increase count but I m having problems replacing the old count with the new count value. I know sed looks like the obvious choice but i cant seem to get it to work and as far as I know all sed's output go to a file not the same line...Smilie

Code:
for line in `cat Final`  
do
    echo -e "$line"
    count=`echo $line | cut -d ',' -f 4`
    etime=`echo $line | cut -d "," -f 1`
    echo  $etime
    echo  $count   
    sytime=`date +%s`
    dif=$(( $sytime - $etime ))
    echo $dif
    if [ $dif -ge 900 ];then
	  echo true
             newcount=$(( $count + 1 ))	
	  tline= sed s/"$count"/"$newcount"/ $line 
	  $line = $tline
             echo $newcount
	  echo $line
		
    else 
	  echo flase
    fi		
done

Its a Bash Script

Last edited by abilash.amara; 12-08-2009 at 03:24 PM..
# 2  
Old 12-08-2009
from the looks of it
Code:
tline= sed s/"$count"/"$newcount"/ $line

you should be reading Final, not $line because sed can only read files, not lines
# 3  
Old 12-08-2009
Well I dont want to read the whole file as there are many lines with such a combination of value. thats why i need to do so line be line check and replace the that specific lines count value. Any idea how to do it ? Any other commands that will do it will also do fine
# 4  
Old 12-08-2009
what you can do is read the line and place it into a file. that way you can use sed and not change much of the code. just
Code:
echo $line > temp

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

awk manipulation

Hallo Family, I have csv file which has over a million records in it. All i want to do is to change field 2 to have the same value as field 10. sample file:Now 0860093239,Anonymous,unconditional,+27381230283,Anonymous,unconditional,y,public,,2965511477:0A Desired output: ... (2 Replies)
Discussion started by: kekanap
2 Replies

3. Programming

bit manipulation

what is the difference b/w 1) #define TI_ZN (1 << 1) #define TI_ZN (1 << 2) and 2) #define TI_ZN 2 #define TI_ZN 4 Instead of using left shift we can assign the value 2 directly? Or there is a reason behind this to use shift operator?... (4 Replies)
Discussion started by: powyama
4 Replies

4. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

5. Shell Programming and Scripting

Line number based manipulation

Hi I have a case where I am grabbing patterns and subsequent lines using sed -n -e '/regex/{$!N;p;}' This returns just the regex line when it is the last line of my file. Now I may have even number of lines in some cases (regex never at end) and odd in very rare cases. If the line... (6 Replies)
Discussion started by: jamie_123
6 Replies

6. Shell Programming and Scripting

Command output string manipulation possible in one line?

This has been bothering me for 3 days. $> hostname cepsun64amd And I just want "cepsun", I would normally do h=`hostname`; ${h%%64*} But I am looking for a one-liner just for my own knowledge, because if there is a way to do this, I should know it by now. Anyway, so is this... (2 Replies)
Discussion started by: Ryan.
2 Replies

7. UNIX for Dummies Questions & Answers

Line & File Manipulation - add spaces between characters

Is there an awk, sed, vi or any line command that adds Field Separators (default spaces) to each line in a file? $cat RegionalData 12FC2525MZLP8266900216 12FC2525MZLP8266900216 12FC2525NBLP8276900216 12FC2525NBLP8276900216 Desired results: 1 2 F C 2525 MZ LP 826 690 02 16 1 2 F C... (2 Replies)
Discussion started by: MS75001
2 Replies

8. Shell Programming and Scripting

String Manipulation

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" (4 Replies)
Discussion started by: proactiveaditya
4 Replies

9. Shell Programming and Scripting

string manipulation

Hi all, see i have a script that takes few arguments. first one is command we do on file, next is file (mostly txt file with lot of data) third is destination where we do something with data in file. Since im new in scripting, and im learning as i go, i need some hint how to manipulate that... (3 Replies)
Discussion started by: ajemrunner
3 Replies

10. UNIX for Dummies Questions & Answers

manipulation

hi, i have got a table with n number of rows and 2 columns..how can i get get 1 row at a time using any unix command without copying to any file? Thanks and Regards vivek.s (13 Replies)
Discussion started by: vivekshankar
13 Replies
Login or Register to Ask a Question