Need Help!!! For changing the content of the line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help!!! For changing the content of the line
# 1  
Old 01-15-2012
Need Help!!! For changing the content of the line

I need to change the content of the line after I grep it.

The line is :

Code:
Date SNWD.I-1 (in)  WTEQ.I-1 (in)  PREC.I-1 (in)  TOBS.I-1 (degC)  TMAX.D-1 (degC)  TMIN.D-1 (degC)  TAVG.D-1 (degC)

I want to change the second column (SNWD.I-1(in)) to SNWD.I-1(m), how could I do that?

I use csh script.

Thanks

Last edited by Scott; 01-15-2012 at 02:07 PM.. Reason: Code tags
# 2  
Old 01-15-2012
Let awk "grep" it and change it as well -
Code:
awk '$2=="SNWD.I-1(in)"  {$2="SNWD.I-1(m)"} {print $0}'  inputfile > newfile

# 3  
Old 01-15-2012
Quote:
Originally Posted by jim_mcnamara
Let awk "grep" it and change it as well -
Code:
awk '$2=="SNWD.I-1(in)" {$2="SNWD.I-1(m)"} {print $0}' inputfile > newfile
There are a couple typos in that awk command. First, he has a space between 'SNWD.I-1' and '(in)', so he'll have to change the third field, not second. And the print statement should be inside the previous action, not as a separate one (thus printing each line). Something like this:
Code:
 awk '$2=="SNWD.I-1" {$3="(m)"; print $0}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Changing file content in perl

Hi All, I have a file content like this. #<clear_category_list> #<include file="SUITE:Provision-FLEXPONDER_FAC.inc"> #<include file="CAT:SYSTEM:SAS_U23.inc"> #<include file="CAT:PRIORITY:10.inc"> #<include file="CAT:FAC_TYPE:OC48.inc"> #<include file="CAT:FAC_TYPE:OC192.inc">... (2 Replies)
Discussion started by: Syed Imran
2 Replies

2. Shell Programming and Scripting

Help with add new line in between each content

Input file: 48458951 49529947 46700865 46207063 52639785 47012578 55872838 49258996 Desired output file: 48458951 49529947 46700865 46207063 (1 Reply)
Discussion started by: perl_beginner
1 Replies

3. Shell Programming and Scripting

changing files content with sed or awk

Hi, Example File: (jumped, bumped, ) how to jumped, FROM tree; EXIT I have some hundreads of files like this with the different words and I want to remove the comma before the bracket and also I have to remove the comma before FROM word. I am trying to use this command : awk '... (5 Replies)
Discussion started by: rajshashi
5 Replies

4. UNIX for Dummies Questions & Answers

Changing file content based on file header

Hi, I have several text files each containing some data as shown below: File1.txt >DataHeader Data... Data... File2.txt >DataHeader Data... Data... etc. What I want is to change the 'DataHeader' based on the file name. So the output should look like: File1.txt >File1 ... (1 Reply)
Discussion started by: Fahmida
1 Replies

5. Shell Programming and Scripting

Reading several files and summing their content line-by-line

Hey, I am gettin a bit crazy with my script. I have several input datas with the same name (5.ill) in different folders (daysim_01, daysim_02, etc.). The 4. column of each of the data has to be summed with each other and then hass to be written in one new file. So file1: 1 1 0 1 2 1 1 2 ... (7 Replies)
Discussion started by: ergy1983
7 Replies

6. UNIX for Advanced & Expert Users

Search Parameter in first line and replace next line content

Hi, I need help. I have XML file as below &lt;a n=&quot;infoLevel&quot;&gt; &lt;v s=&quot;true&quot;/&gt; &lt;/a&gt; &lt;a n=&quot;localAddr&quot;&gt; &lt;v s=&quot;server.host.com&quot;/&gt; &lt;/a&gt; &lt;a n=&quot;ListenPort&quot;&gt; &lt;v s=&quot;21111&quot;/&gt; &lt;/a&gt; I need to find variable "ListenPort" in line and then replace... (4 Replies)
Discussion started by: rdtrivedi
4 Replies

7. Shell Programming and Scripting

changing line on a file

Hi, I want to change on a file this line: vif = into: vif = But there are some conditionals: 1. last part '] of the original line after 00:16:3E:CE:23:14' ] may vary to 00:16:3E:CE:23:14' ] or 00:16:3E:CE:23:14 ' ] 2. The second mac adrress of the line I need,... (4 Replies)
Discussion started by: iga3725
4 Replies

8. Shell Programming and Scripting

changing colomn to the line

I have a file which has only one colomn of numbers,ex: 122 173 292 400 979 2152 2339 2376 2387 2446 2450 What ksh / unix command should I use to create a file in which those numbers will be in one line,like this 122 173 292 400 979 .... etc Thanks a lot for help (9 Replies)
Discussion started by: aoussenko
9 Replies

9. Shell Programming and Scripting

How to replace a line content

Hi Experts, I have binary files contain an ID Line as: : : $Header: FNDSCMON.fmb 115.6 2000/01/11 10:26:10 pkm ship$ : : where the ID Line format is: $Header: <File_Name> <Version> <Last_update_date_time> pkm ship$ In this Example: File_Name = FNDSCMON.fmb Version = 115.6... (13 Replies)
Discussion started by: victorcheung
13 Replies

10. Shell Programming and Scripting

Changing Line Number of a File

Example: O o x What I would like to do is to rename the first column of the above file without affecting the format. The output should look like the following: Output: O o x #! /bin/ksh cd $HOME/lib/.Lee #nl = no. of lines. nl=`grep 'X' ex | wc -l` #ln = line no. ln=1 (17 Replies)
Discussion started by: ilak1008
17 Replies
Login or Register to Ask a Question