Replacing underscore with white space after comma.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replacing underscore with white space after comma.
# 8  
Old 06-22-2009
try this
nawk -F"," '{gsub("_"," ",$2);print}' OFS="|" file

"AL1_1|AL1 1|"
"AL1_1.AL1_1A.AL1_1AE|AL1 1AE|"
"AL1_1.AL1_1A.AL1_1AG|AL1 1AG|"
"AL1_1.AL1_1A.AL1_1AJ|AL1 1AJ|"
"AL1_1.AL1_1B.AL1_1BH|AL1 1BH|"
# 9  
Old 06-22-2009
Quote:
Originally Posted by r_t_1601
try this
nawk -F"," '{gsub("_"," ",$2);print}' OFS="|" file

"AL1_1|AL1 1|"
"AL1_1.AL1_1A.AL1_1AE|AL1 1AE|"
"AL1_1.AL1_1A.AL1_1AG|AL1 1AG|"
"AL1_1.AL1_1A.AL1_1AJ|AL1 1AJ|"
"AL1_1.AL1_1B.AL1_1BH|AL1 1BH|"
The OP don't ask for a pipe symbol as fieldseparator, and this is the exact command I gave, what is the surplus value of your solution?

Regards
# 10  
Old 06-22-2009
try it, it's working on large record

sed 's/,A[^\,]*/,AL1 1AE/g' <filename> > <filename>
# 11  
Old 06-22-2009
Thanks very much! nawk worked perfectly with awk -F, '{gsub("_"," ",$2)}1' OFS="," file > newfile
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a space with underscore in a file

i have a file with following data. { EqName "Tan 1" .... .... } { EqName "Sin 2" ... ... } I have to replace the value of EqName to Tan_1 and Sin_2 in file.Can i use sed or awk ? cat file|grep EqName|awk '{print $2 $3}'|sed -i 's//_/g' I tried with this but it... (2 Replies)
Discussion started by: Jag02
2 Replies

2. Shell Programming and Scripting

Add white space

hi guys how can i add spacein file name with sed if strings have no space around dash input 19-20 ( 18-19 ) ABC-EFG output after add white space 19 - 20 (18 - 19 ) ABC - EFG thx in advance (2 Replies)
Discussion started by: mhs
2 Replies

3. Shell Programming and Scripting

Replacing white spaces in filename

Hi; In following code find LOG_DIR -type f | while read filename; do echo $filename; done I want to precede each white space encountered in filename with \ so that when i use $filename for running some commands in do...done,it wont give me an error. will appreciate ur help in this.... (1 Reply)
Discussion started by: ajaypadvi
1 Replies

4. Shell Programming and Scripting

Using of gsub function in AWK to replace space by underscore

I must design a UNIX script to monitor files whose size is over a threshold of 5 MB in a specific UNIX directory I meet a problem during the for loop in my script. Some file names contain spaces. ls -lrt | awk '$5>=5000000 && length($8)==5 {gsub(/ /,"_",$9); print};' -rw-r--r-- 1 was61 ... (2 Replies)
Discussion started by: Scofield38
2 Replies

5. Shell Programming and Scripting

sed help - replacing 6th comma with a space

Hi, How can I replace the 6th comma on each line (of a csv) with a space? Any online tutorials with plenty of examples using sed would be very useful. Alex (2 Replies)
Discussion started by: mcclunyboy
2 Replies

6. Shell Programming and Scripting

How to Use Sed Command to replace white spaces with comma from between two fields - Mayank

SHELL SCRIPT Hi I have a file in the following format Mayank Sushant Dheeraj Kunal ARUN Samir How can i replace the white space in between and replace them with a comma?? The resultant output should be Mayank,Sushant Dheeraj,Kunal ARUN,Samir i tried using sed -e... (8 Replies)
Discussion started by: mayanksargoch
8 Replies

7. Shell Programming and Scripting

Suppressing space replacing by comma

hi i want to replace spaces by comma my file is ADD 16428 170 160 3 WNPG 204 941 No 204802 ADD 16428 170 160 3 WNPG 204 941 No 204803 ADD 16428 170 160 3 WNPG 204 941 No 204804 ADD... (9 Replies)
Discussion started by: raghavendra.cse
9 Replies

8. Shell Programming and Scripting

Help with sed and replacing white spaces with commas

Dear all, I am in a bit of a quandary. I have 400 text files which I need to edit and output in a very specific way. Here is a sample text file copied from gedit ... The columns will come out a bit messed up but when I cat <file>, it gives a table with six columns (0-28, tot lob vol, vcsf,... (6 Replies)
Discussion started by: antonz
6 Replies

9. UNIX for Dummies Questions & Answers

SED with White Space

Dear Members, Suppose i have a variable test which stores a string as below: test='John drives+++++++++a+++++car' now i want to use sed on the above variable and replace + with a white space, so that i get echo $test should give me 'john drives a car' Between... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

10. Shell Programming and Scripting

Regex/sed - matching any char,space,underscore between : and /

trying to remove the portion in red: Data: mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly.sql output to be: mds_ar/bin/uedw92wp.ksh: wkly.sql mds_ar/bin/uedw92wp.ksh: wkly.sql SED i'm trying to use: sed 's/:+\//: /g' input_file.dat >... (11 Replies)
Discussion started by: danmauer
11 Replies
Login or Register to Ask a Question