awk/sed problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk/sed problem
# 1  
Old 12-14-2011
awk/sed problem

I have a bunch of files I need to change a letter to another letter only in the first column of a space delimited file. The problem is that after the first column, there's comments and such that cause problems with awk.

Here's what my data looks like:
Code:
16a28.0a27.0a26.0a25.0a24.67.255.200
144a28.128a27.128a26.128a25.0a24.67.255.200
128a28.128a27.128a26.128a25.0a24.67.255.200
120a29.112a28.96a27.64a26.0a25.0a24.67.255.200
12a32.12a31.12a30.8a29.0a28.0a27.0a26.0a25.0a24.67.255.200
112a29.112a28.96a27.64a26.0a25.0a24.67.255.200
10a32.10a31.8a30.8a29.0a28.0a27.0a26.0a25.0a24.67.255.200
0a24.67.255.200
0a24.56.255.200
0a24.55.255.200
0a25.0a24.122.255.200

Again, this is a space delimited file and this is just the first column. I want to change the a to b and not affect the rest of the data.

Thanks,
Dave
# 2  
Old 12-14-2011
Try:
Code:
awk '{gsub("a","b",$1)}1' file

# 3  
Old 12-14-2011
Quote:
Originally Posted by bartus11
Try:
Code:
awk '{gsub("a","b",$1)}1' file

Using the code of Bartus, I thing that he wants is:
Code:
soy@machine: temporal > nawk -F"." '{gsub("a","b",$1)}1' uno.txt
16b28 0a27 0a26 0a25 0a24 67 255 200                                
144b28 128a27 128a26 128a25 0a24 67 255 200                         
128b28 128a27 128a26 128a25 0a24 67 255 200                         
120b29 112a28 96a27 64a26 0a25 0a24 67 255 200                      
12b32 12a31 12a30 8a29 0a28 0a27 0a26 0a25 0a24 67 255 200          
112b29 112a28 96a27 64a26 0a25 0a24 67 255 200                      
10b32 10a31 8a30 8a29 0a28 0a27 0a26 0a25 0a24 67 255 200           
0b24 67 255 200                                                     
0b24 56 255 200                                                     
0b24 55 255 200                                                     
0b25 0a24 122 255 200

# 4  
Old 12-14-2011
Code:
[root@hostname test]# cat input
16a28.0a27.0a26.0a25.0a24.67.255.200 16a28.0a27.0a26.0a25.0a24.67.255.200
144a28.128a27.128a26.128a25.0a24.67.255.200 144a28.128a27.128a26.128a25.0a24.67.255.200

Code:
[root@hostname test]# perl -lane '$F[0]=~s/a/b/g; print "@F"' input
16b28.0b27.0b26.0b25.0b24.67.255.200 16a28.0a27.0a26.0a25.0a24.67.255.200
144b28.128b27.128b26.128b25.0b24.67.255.200 144a28.128a27.128a26.128a25.0a24.67.255.200

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk script problem

Hi All I am having a file as shown below File1# modyle 1 { test jsj hhsjh 13e3 jsjjs } memP(dbg_trace) { ajjs jsjs jsjs Test(claer) { jsjs (7 Replies)
Discussion started by: kshitij
7 Replies

2. Shell Programming and Scripting

Problem with output awk and sed

I have file, i am extracting email address from file. but problem is that output is very ugly. I am using this command REMOVED "CSS OFFENDING CODE"... While original filename have no such character. Please suggest. (20 Replies)
Discussion started by: learnbash
20 Replies

3. Shell Programming and Scripting

Some problem with awk or sed in if conditions

#set -x path=`pwd` while read line do dd=`echo $line|awk -F"," '{print $1}'|awk -F"/" '{print $2}'` if then mm=`echo $line|awk -F"," '{print $1}'|awk -F"/" '{print $1}'` yy=`echo $line|awk -F"," '{print $1}'|awk -F"/" '{print $3}'` var=`echo $line|awk -F"," '{print $2}'` var1=`echo... (2 Replies)
Discussion started by: nikhil jain
2 Replies

4. Shell Programming and Scripting

awk and sed problem

Hi, I am able to generate a csv file which has 3 columns. But the header is not coming out exactly i.e it doesnot have a comma in between it but the data is getting produced with the comma. The first line i.e the header is coming out as:- Counter Number Counterparty1 Counterparty2 ... (10 Replies)
Discussion started by: scripter12
10 Replies

5. Shell Programming and Scripting

Another parsing line awk or sed problem

Hi, After looking on different forums, I'm still in trouble to parse a parameters line received in KSH. $* is equal to "/AAA:111 /BBB:222 /CCC:333 /DDD:444" I would like to parse it and be able to access anyone from his name in my KSH after. like echo myArray => display 111 ... (1 Reply)
Discussion started by: RickTrader
1 Replies

6. Shell Programming and Scripting

Problem facing with sed and awk

Hi All, I have a got a problem .. I have t files as below: 1.txt contains ----- ----- ----- column 1, "cat", column 24, "dog", column 100, "rat", ----- ----- ----- 2.sh should contain ----- ----- ----- awk 'BEGIN { printf ("%1s","cat")}' (19 Replies)
Discussion started by: jisha
19 Replies

7. Shell Programming and Scripting

awk...sed problem

Hi guys, I am tryingto delete or ignore columns in a large dataset using 'sed'. For example, I have the following dataset: - 20060714,X.XX,1,043004,Q,T,24.0000,1,25.5000,4, 20060714,X.XX,1,081209,Q,T,24.0000,1,25.5000,5, As you can see, there are 10 columns here and the table that I am... (1 Reply)
Discussion started by: aarif
1 Replies

8. Shell Programming and Scripting

awk,sed or cut problem

Good afternoon, Sir's, I would like to seek your assistance regarding on this matter. $cat file1 111 aaaa bbb aass aaa files file1 temp temp1 pix 222 11 22 1 33 44 desired output: aaaa bbb aass files file1 temp1 222 11 22 1 33 44 thanks (7 Replies)
Discussion started by: invinzin21
7 Replies

9. Shell Programming and Scripting

awk & sed problem

Hello, I am new to shell scripting. I want to optimize my one of the script. I have one file and i want to remove selected zones for domains from that file.In this file i have almost 3500 zones for domains.Sample data for the file.... named.backup... (0 Replies)
Discussion started by: nrbhole
0 Replies

10. UNIX for Dummies Questions & Answers

sed/awk String problem

I would appreciate it if any one can guide me in using awk perhaps sed in extracting some values from a long string. here is an example. .......some lines here........ ........ aaaa bbbb cccc ddddd eeeee fffff gggg (time:hhhh)........ ......some lines here also.......... How can I extract... (2 Replies)
Discussion started by: odogbolu98
2 Replies
Login or Register to Ask a Question