fill a NIL into the blank field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting fill a NIL into the blank field
# 1  
Old 03-23-2007
fill a NIL into the blank field

Hello,

I have a record which split with "," I would like to check..if the field is empty and it will field "NIL" into the field.

input

45111,40404,peter,,0303403,0,030304,john,,9,0,

output

45111,40404,peter,NIL,0303403,0,030304,john,NIL,9,0,
# 2  
Old 03-23-2007
One of the many ways...

Code:
echo "45111,40404,peter,,0303403,0,030304,john,,9,0," | sed -e "s/,,/,NIL,/g"

# 3  
Old 03-23-2007
Plz try this..

Quote:
data='45111,40404,peter,,0303403,0,030304,john,,9,0,'
echo $data | sed 's/,,/,NIL,/g'
or

Quote:
echo ${data//,,/,NIL,}
# 4  
Old 03-23-2007
Quote:
Originally Posted by jacoden
Plz try this..



or
but you echo one record.....ONLY
I have a file which over 100,000 record and I would to fill all records like this format...any idea
# 5  
Old 03-23-2007
Quote:
Originally Posted by happyv
but you echo one record.....ONLY
I have a file which over 100,000 record and I would to fill all records like this format...any idea
Code:
sed -e "s/,,/,NIL,/g" file > tmp
mv tmp file

# 6  
Old 03-23-2007
Quote:
Originally Posted by anbu23
Code:
sed -e "s/,,/,NIL,/g" file > tmp
mv tmp file

Great! work fine
# 7  
Old 03-23-2007
also, how can i check the specify field (such as field no#11 and the value is "0", than change to "0:00")?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a blank field and replace values to NA

Hi All, i have a file like col1 col2 col3 13 24 NA 12 13 14 11 12 13 14 22 NA 18 26 NA in this file if i found "NA" other values in the line are also replace by NA Could you help me! (7 Replies)
Discussion started by: Shenbaga.d
7 Replies

2. Shell Programming and Scripting

Find a blank field

Find a blank field Hi I have set of fields that have some blank values, how to find that and get its line noumbers in output file. Ex: Col1 col2 col3 11 ss 103 12 104 13 105 14 se 106 (2 Replies)
Discussion started by: Shenbaga.d
2 Replies

3. Shell Programming and Scripting

Adding an additional blank field to a file

Hi, I have the following file, I'd like to add an additional blank field to this file This is a tab delimited file, I have tried the same thing on excel, but looking for a unix solution. Here is my input: Country Postal Admin4 StreetBaseName StreetType HUN 2243 Kóka Dózsa György ... (3 Replies)
Discussion started by: ramky79
3 Replies

4. Shell Programming and Scripting

Help with removal of blank spaces from the second field!

Hi everyone.. I'm trying to eliminate multiple whitespaces from a file.. I must make use of shell script to eliminate whitespaces.. Take a look at the sample file 1 int main() 2 { 3 int a,b; 4 printf("Enter the values of a and b"); 5 scanf("%d%d",&a,&b); 6 if(a>b) ... (6 Replies)
Discussion started by: abk07
6 Replies

5. Shell Programming and Scripting

Find and replace blank in the last field

Hi all, I have a huge file and I need to get ride of the fields 6-11 and replace the blanks in field 5 with a missing value(99999). 159,93848,5354,343,67898,45,677,5443,434,5545,45 677,45545,3522,244, 554,54344,3342,456, 344,43443,2344,444,23477... (12 Replies)
Discussion started by: GoldenFire
12 Replies

6. Shell Programming and Scripting

Fill the empty line by adding line before blank line

FIle A "A" 2 aa 34 3 ac 5 cd "B" 3 hu 67 4 fg 5 gy output shud be A"" 2 aa 34 "A" 3 ac 34 "A" 5 cd 34 "B" 3 hu 67 "B" 4 fg 67 "B" 5 gy 67 (6 Replies)
Discussion started by: cdfd123
6 Replies

7. Programming

Zero Fill 10 position field

Hi everyone, I am using shell scripting on a Unix SCO box. It calls a C program named zerofill. I do not know anything about C. I am having an issue with a hash total that should only be zero filled 10 positions but the record has 11 positions. DEBUG RESULTS + nice -n -5 bc -l /tmp/fhash8395... (0 Replies)
Discussion started by: ski
0 Replies

8. Shell Programming and Scripting

how to include field separator if there are blank fields?

Hi, I have the following data in the format as shown (note: there are more than 1 blank spaces between each field and the spaces are not uniform, meaning there can be one blank space between field1 and field2 and 3 spaces between field3 and field4, in this example, # are the spaces in between... (19 Replies)
Discussion started by: ReV
19 Replies

9. Shell Programming and Scripting

awk: How to check if field is blank?

In awk, I'd like to check if a field is blank. And by blank I mean, the field could be "" or " " In other words, the field could either be empty, or be filled with spaces. Would the regex look like this? $5 ~ // { Action }? What other ways are there? Hmm.. in any case I think... (7 Replies)
Discussion started by: yongho
7 Replies
Login or Register to Ask a Question