How to change a number on a specific line with cshell or shell?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to change a number on a specific line with cshell or shell?
# 8  
Old 03-22-2012
create a file addfr.awk and put the below contents inside the addfr.awk


Code:
BEGIN { A["FRR1"]=0.11; A["FRR4"]=0.13 }

A[$1] {
        V=substr($0, 24, 5);
        V += A[$1]
        $0=substr($0, 0, 23) sprintf("%5s", V) substr($0, 29);
}
1

And from the command prompt, execute the below command.

Code:
awk -f addfr.awk data > data.out



In the above command, data is the input file, addfr.awk is the awk file. and data.out is the output file

This User Gave Thanks to itkamaraj For This Post:
# 9  
Old 03-22-2012
Power

Quote:
Originally Posted by itkamaraj
create a file addfr.awk and put the below contents inside the addfr.awk


Code:
BEGIN { A["FRR1"]=0.11; A["FRR4"]=0.13 }

A[$1] {
        V=substr($0, 24, 5);
        V += A[$1]
        $0=substr($0, 0, 23) sprintf("%5s", V) substr($0, 29);
}
1

And from the command prompt, execute the below command.

Code:
awk -f addfr.awk data > data.out



In the above command, data is the input file, addfr.awk is the awk file. and data.out is the output file

THANK YOU very MUCH! I did not realise that it was the code in a file! I should be more careful! Again, Thank you for your kind answers!
# 10  
Old 07-23-2012
I see that it is a little bit complicated I could not understand what is "p" for and when I run the script:

Code:
sezim@localhost#cat gauss.awk
awk '
  {
    for(i=1;i<=NF;i++)                                    # for every field on every line
      if($i~/[A-Z]{5}[0-9]$/){                            # if a field contains a station number
        getline p<f                                       # then get the next noise correction
        split(p,N)                                        # split the fields of the noise correction into array N
        sub($(i+1)+0,sprintf("%.3f",$(i+1)+N[2]),$(i+1))  # substitute the numerical value in the next field with the modified value
      }
  }
  1                                                       # print line
' f=noisedata                                             # set variable f to noise file
sezim@localhost#awk -f gauss.awk mydata
awk: gauss.awk:1: awk '
awk: gauss.awk:1:     ^ invalid char ''' in expression

Is it some kind of expression problem?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

2. Shell Programming and Scripting

Cut from specific line number to a line number

Hi All, I've a file like this.. Sheet1 a,1 a,2 a,3 a,4 a,5 Sheet2 a,6 a,7 a,8 a,9 a,10 Sheet3 a,11 a,12 a,13 (7 Replies)
Discussion started by: manab86
7 Replies

3. Shell Programming and Scripting

How to change a number on a specific lines in a file with shell?

Hello My problem is that I want to change some specific numbers in a file. It is like, 2009 10 3 2349 21.3 L 40.719 27.388 10.8 FRO 7 0.8 1.1LFRO 2.6CFRO 1.1LMAM1 GAP=157 1.69 5.7 5.9 5.8 0.5405E+01 0.4455E+00 0.1653E+02E STAT SP IPHASW D HRMM SECON CODA AMPLIT... (11 Replies)
Discussion started by: miriammiriam
11 Replies

4. Shell Programming and Scripting

new line after specific number character

Hi All, I have input file like this: input1: ( 1083479)=T 158V 1798, T 391V 1896,T 1138V 2273,T 1547V 2477,T 2249V 2917,T 3278V 3234,T 4152V 3495,T 5500V 3631, ( 1083501)=T 181V 1851, T 459V 1954,T 810V 2141,T 1188V 2372,T 1638V 2696,T 2731V 3124,T 4799V 3640,... (5 Replies)
Discussion started by: attila
5 Replies

5. Shell Programming and Scripting

How to read from specific line number in shell script?

I have a text file which is having 30000 lines in it. I have to create a xml file for each 10000 lines until all the lines in the text files are written. Also please help how can i get number of lines in the text file in a shell variable? (19 Replies)
Discussion started by: vel4ever
19 Replies

6. Programming

Cshell help with change colour in print

i want to ask how to change the colour of prompt message from use? and also how to change colour in printing........ i want to change it as blue colour and red colour, but i found many website still don't know how to do. how's the command is wrote? thz really!! (1 Reply)
Discussion started by: wendy1089
1 Replies

7. Shell Programming and Scripting

How would i delete a line at specific line number

Hi guys , I m writing a script to delete a line at particular location. But i m unable to use variable for specifying line number. for example. sed -n '7!p' filename works fine and deletes 7th line from my file but sed -n '$variable!p' filename gives following error. sed: -e... (12 Replies)
Discussion started by: pinga123
12 Replies

8. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

9. UNIX for Dummies Questions & Answers

Change Specific Line of a File

Hi everyone, I am attempting to do something that should be very simple. How do I replace a specific line of a file with different text, and then save that file to its original name? I believe I want to use the sed command with the c option, but I after trying many times, I can't get the right... (10 Replies)
Discussion started by: msb65
10 Replies

10. Shell Programming and Scripting

Adding a columnfrom a specifit line number to a specific line number

Hi, I have a huge file & I want to add a specific text in column. But I want to add this text from a specific line number to a specific line number & another text in to another range of line numbers. To be more specific: lets say my file has 1000 lines & 4 Columns. I want to add text "Hello"... (2 Replies)
Discussion started by: Ezy
2 Replies
Login or Register to Ask a Question