Need to replace text in an awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to replace text in an awk
# 1  
Old 05-10-2005
Need to replace text in an awk

Hey guys:

Running Solaris 5.5.1 and trying to write an easy /bin/sh script. Here is what I am doing...

grep "Total" /workspace_4/local/reports/cust_calls_5ess.050510 | awk '{print $4 "\t" $7 $8 $9 $10 $11 $12 $13 $14}'

It renders the following results...

315268 CLARKSONUNIVERSITYis:1485
516286 BROOKHAVENHOSPITALis:8372
516231 CITIBANKis:1247
978796 DMATSAYERis:3447
718239 NYSBRONXCHILDRENPSY.CTRis:778
508875 DMATSFRAM2is:5759
781378 DMATSLEXTN2is:20826
914285 CITYOFWHITEPLAINSis:5154

What I would like to do is replace the "is:" above with a <TAB>, so that it looks more like this...

315268 CLARKSONUNIVERSITY 1485
516286 BROOKHAVENHOSPITAL 8372
516231 CITIBANK 1247
978796 DMATSAYER 3447
718239 NYSBRONXCHILDRENPSY.CTR 778
508875 DMATSFRAM2 5759
781378 DMATSLEXTN2 20826
914285 CITYOFWHITEPLAINS 5154

The tricky part is that I have to print $7 thru $14 everytime so that I make sure to capture all of the info. I can't simply leave off $13 or $14, for example, because I might miss data dependin on how long the line is.

Any ideas???

-cd
# 2  
Old 05-10-2005
The simplest way would be to pipe your commands through sed....
Code:
grep blah | awk blah | sed 's/is/	/'

You can insert the tab literally, or use Ctrl-V Ctrl-I

Cheers
ZB
# 3  
Old 05-10-2005
Worked like a champ. THANKS!!

-cd
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with awk or sed Command to Replace Text in Files

Hello Everyone, I have many files like so: file1.txt file2.txt file3.txt Within each file I have many lines of random text separated by commas like so: abcAAA,123,defAA,456777,ghiA,789 jklB,101,mnoBBB,11211,pqrB,13111 stuCC,415,vwxCCCC,161,yzaC,718 I am trying to use SED or AWK to... (4 Replies)
Discussion started by: D3U5X
4 Replies

2. Debian

Using awk and sed to replace text

Good Day Every one I have a problem finding and replacing text in some large files that will take a long time to manually edit. Example text file looks like this #Example Large Text File unix linux dos squid bind dance bike car plane What im trying to do is to edit all the... (4 Replies)
Discussion started by: linuxjunkie
4 Replies

3. Shell Programming and Scripting

awk text replace

I have a record in below format | msg1 | msg2 | msg3 | - | msg4 I am looking for output mm/mon/yyyy | 01:23:59 | msg1 | msg2 | msg3 | msg4 I am trying to look in awk to make the above change So far to avoid columns i tried cat file | awk -F'|' '{$2=$3="";print $0}' but i... (2 Replies)
Discussion started by: Tomlight
2 Replies

4. Shell Programming and Scripting

Search and replace from file in awk using a 16 bit text file

Hello, Some time ago a helpful awk file was provided on the forum which I give below: NR==FNR{A=$0;next}{for(j in A){split(A,P,"=");for(i=1;i<=NF;i++){if($i==P){$i=P}}}}1 While it works beautifully on English and Latin characters i.e. within the ASCII range of 127, the moment a character beyond... (6 Replies)
Discussion started by: gimley
6 Replies

5. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

6. Shell Programming and Scripting

using sed/awk to replace a block of text in a file?

My apologies if this has been answered in a previous post. I've been doing a lot of searching, but I haven't been able to find what I was looking for. Specifically, I am wondering if I can utilize sed and/or awk to locate two strings in a file, and replace everything between those two strings... (12 Replies)
Discussion started by: kiddsupreme
12 Replies

7. Shell Programming and Scripting

Find and add/replace text in text files

Hi. I would like to have experts help on below action. I have text files in which page nubmers exists in form like PAGE : 1 PAGE : 2 PAGE : 3 and so on there is other text too. I would like to know is it possible to check the last occurance of Page... (6 Replies)
Discussion started by: lodhi1978
6 Replies

8. Shell Programming and Scripting

text file search and replace with awk

hello all greeting for the day i have a text file as the following text.xml abcd<FIELD>123.456</FIELD>efgh i need to replace the value between <FIELD> and </FIELD> by using awk command. please throw some light on this. thank you very very much Erik (5 Replies)
Discussion started by: erikshek
5 Replies

9. Shell Programming and Scripting

How to replace a range of text with sed or awk?

Howdy! I'm trying to automate editing of a configuration file (custom.conf for GDM). I need to find every line between a line that starts with "" and the next line that starts with "", I want to preserve that line, but then delete all the lines in that configuration section and then insert... (3 Replies)
Discussion started by: TXTad
3 Replies

10. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies
Login or Register to Ask a Question