Replace 2nd Column | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Replace 2nd Column

Shell Programming and Scripting


Tags
replace

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-07-2013
attila attila is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 5 August 2014, 3:58 AM EDT
Posts: 54
Thanks: 27
Thanked 0 Times in 0 Posts
Replace 2nd Column

Dear All,

I have data like this,

input.txt


Code:
A    0B 1828
C  100D 1666,C  200D 1727,C  300D 1783,
A    0B 1786
C  200D 1727,C  100D 1666,C  300D 1783,
C  400D 1812,C  600D 1869,C  500D 1841,
C  400D 1812,C  500D 1841,C  600D 1869,
A    0B 1349
C  200D 1727,C  300D 1783,C  100D 1666,
C  400D 1812,C  600D 1869,C  500D 1841,
C  400D 1812,C  500D 1841,C  600D 1869,
A    0B 1129
C  200D 1727,C  300D 1783,C  600D 1869,
C  400D 1812,C  100D 1666,C  500D 1841,
A    0B 1702
C  100D 1666,C  300D 1783,C  600D 1869,
C  400D 1812,C  500D 1841,C  200D 1727,
A    0B 1897
C  200D 1727,C  300D 1783,C  100D 1666,
.
.
.

expected result
result.txt

Code:
A    0B 1500
C  100D 1666,C  200D 1727,C  300D 1783,
A    0B 1500
C  200D 1727,C  100D 1666,C  300D 1783,
 C  400D 1812,C  600D 1869,C  500D 1841,
C  400D 1812,C  500D 1841,C  600D 1869,
A    0B 1500
C  200D 1727,C  300D 1783,C  100D 1666,
 C  400D 1812,C  600D 1869,C  500D 1841,
C  400D 1812,C  500D 1841,C  600D 1869,
A    0B 1500
C  200D 1727,C  300D 1783,C  600D 1869,
 C  400D 1812,C  100D 1666,C  500D 1841,
A    0B 1500
C  100D 1666,C  300D 1783,C  600D 1869,
 C  400D 1812,C  500D 1841,C  200D 1727,
A    0B 1500
C  200D 1727,C  300D 1783,C  100D 1666,
.
.
.

Thanks for Advance,

Attila
Sponsored Links
    #2  
Old 01-07-2013
sathyaonnuix's Avatar
sathyaonnuix sathyaonnuix is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 26 June 2014, 12:23 PM EDT
Posts: 129
Thanks: 35
Thanked 14 Times in 13 Posts

Code:
# cat file
A    0B 1828
C  100D 1666,C  200D 1727,C  300D 1783,
A    0B 1786
C  200D 1727,C  100D 1666,C  300D 1783,
C  400D 1812,C  600D 1869,C  500D 1841,
C  400D 1812,C  500D 1841,C  600D 1869,
A    0B 1349
C  200D 1727,C  300D 1783,C  100D 1666,
C  400D 1812,C  600D 1869,C  500D 1841,
C  400D 1812,C  500D 1841,C  600D 1869,
A    0B 1129
C  200D 1727,C  300D 1783,C  600D 1869,
C  400D 1812,C  100D 1666,C  500D 1841,
A    0B 1702
C  100D 1666,C  300D 1783,C  600D 1869,
C  400D 1812,C  500D 1841,C  200D 1727,
A    0B 1897
C  200D 1727,C  300D 1783,C  100D 1666,


Code:
# awk '/^A/{$3=1500}1' file
A 0B 1500
C  100D 1666,C  200D 1727,C  300D 1783,
A 0B 1500
C  200D 1727,C  100D 1666,C  300D 1783,
C  400D 1812,C  600D 1869,C  500D 1841,
C  400D 1812,C  500D 1841,C  600D 1869,
A 0B 1500
C  200D 1727,C  300D 1783,C  100D 1666,
C  400D 1812,C  600D 1869,C  500D 1841,
C  400D 1812,C  500D 1841,C  600D 1869,
A 0B 1500
C  200D 1727,C  300D 1783,C  600D 1869,
C  400D 1812,C  100D 1666,C  500D 1841,
A 0B 1500
C  100D 1666,C  300D 1783,C  600D 1869,
C  400D 1812,C  500D 1841,C  200D 1727,
A 0B 1500
C  200D 1727,C  300D 1783,C  100D 1666,

The Following User Says Thank You to sathyaonnuix For This Useful Post:
attila (01-07-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace 2nd column in file sdosanjh Shell Programming and Scripting 14 12-18-2012 03:05 AM
Replace 2nd column for each line in a csv file with fixed string+random number tententen Shell Programming and Scripting 7 10-27-2011 11:54 AM
Replace 2nd column of CSV file with numbers on line ffdstanley Shell Programming and Scripting 5 09-04-2011 09:57 AM
comparing column of two different files and print the column from in order of 2nd file CAch Shell Programming and Scripting 14 08-24-2011 01:45 PM
Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 rydz00 Shell Programming and Scripting 7 11-09-2010 10:28 AM



All times are GMT -4. The time now is 02:59 PM.