Changing one number in all files using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing one number in all files using awk
# 1  
Old 09-18-2010
Question Changing one number in all files using awk

Hi

I want to change the number 70 mentioned in my file to 76 by using awk. I know how to change all same digits but not one particular number.

I have 29 files almost similar to this. One of my files looks like

Code:
#Input file for 200K NPT molecular dynamics of final 70%XL made from 58.5% X-Linked EPON:DETDA hardener at 63.6117 Angs final box size (with 100% VDW and interchanged columns)

units real
dimension 3
boundary p p p

atom_style molecular

neighbor 4.0 bin
neigh_modify every 1 delay 0 check yes page 1000000 one 100000

echo screen

#OPLS potentials

bond_style harmonic
angle_style harmonic
dihedral_style opls

pair_style lj/cut/opt 10.0
pair_modify mix arithmetic

read_data DataFile_432isto216_70XLfrom58point5XL_7thmin.xyz

#dynamics commands
#initial velocities

compute 1 all temp
compute 2 all pressure 1
compute 3 all pe
velocity all create 200.0 200.0

#fixes

fix 1 all npt 200.0 200.0 10.0 xyz 1.0 1.0 10.0 drag 2.0

dump EPONDETDA all xyz 100000.0 epon432isto216_70XLfrom58point5XL_dumpNPT_200Kdynamics.xyz

#run

timestep 0.4
thermo 100
thermo_modify lost warn
thermo_style custom step temp pe ke etotal evdwl epair ebond eangle edihed emol press vol

run 500000

Any suggestions? Smilie

Last edited by Scott; 09-18-2010 at 08:54 PM.. Reason: Code tags, please...
# 2  
Old 09-18-2010
Hi,

Why don't you try to use sed instead...., like this.

Code:
sed ’s/70XL/76XL/g’ input_file > output_file


BTW - If you have too many files, you can process them with a script using a "for i in " for example.


Thanks,

Marco,

Last edited by Scott; 09-18-2010 at 11:24 PM..
This User Gave Thanks to ocramas For This Post:
# 3  
Old 09-19-2010
Code:
ruby -i.bak -ne 'print if gsub(/70XL/,"76XL")' file

# 4  
Old 09-19-2010
by awk, there is sub or gsub function to do the same job.

Code:
awk '{gsub(/70XL/,"76XL")}1' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk error when increasing number of files in folder

I have a folder with several files of which I want to eliminate all of the terms that they have in common using `awk`. Here is the script that I have been using: awk ' FNR==1 { if (seen++) { firstPass = 0 outfile = FILENAME "_new" ... (4 Replies)
Discussion started by: owwow14
4 Replies

2. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 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. Shell Programming and Scripting

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

5. Shell Programming and Scripting

reading number of files..one by one in awk script

Hi I have awk script that is reading data from file and printing the result on the monitor....I need to read more than one file .....one by one... and store the result in output file... ---------- Post updated at 06:41 AM ---------- Previous update was at 06:39 AM ---------- please i need... (4 Replies)
Discussion started by: aldreho
4 Replies

6. Shell Programming and Scripting

Changing the sequence number

Hi, I have a data as follow: 1 400 2 239 3 871 4 219 5 543 6 ... 7 ... .. ... .. ... 99 818 100 991 I want to replace the sequence number (column 1) that start from 150. The output should like this: 150 400 151 239 (3 Replies)
Discussion started by: nica
3 Replies

7. Shell Programming and Scripting

How to do a find number of files in awk

Hi, How can i able to do a similar operation to "find" number of files in a folder in an awk? In bash, we could do easily using "find" command. But currently, I am having an awk block and i wanted to extract these information. Please advise. Thanks. (2 Replies)
Discussion started by: ahjiefreak
2 Replies

8. 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

9. Shell Programming and Scripting

awk script to find the number of files

awk script to find the number of files in a directory with their date less than 15-oct-2006 please help (4 Replies)
Discussion started by: uni_ajay_r
4 Replies

10. UNIX for Dummies Questions & Answers

Changing SNMP port number

hi, i am using Sun Solaris 8 (Sparc). Currently there is a SNMP agent running on port 161. How should I change it to port 8001? which file to modify and restart is necessary? pls teach me the information. thanks (8 Replies)
Discussion started by: champion
8 Replies
Login or Register to Ask a Question