how to include field separator if there are blank fields?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to include field separator if there are blank fields?
# 8  
Old 07-12-2005
vgersh99


The o/p wants to detect the absence of field2 and field3.

vino
# 9  
Old 07-12-2005
empty fields are also spaces. but i need them to be shown as a blank in the output.
# 10  
Old 07-12-2005
Quote:
Originally Posted by vino
vgersh99


The o/p wants to detect the absence of field2 and field3.

vino
yes, exactly. the absence of field2 and 3 are not detected. thanks vino for explaining it Smilie
# 11  
Old 07-12-2005
If field2 and field3 always follow a same pattern, then look for its absence, and introduce a ;

Vino
# 12  
Old 07-12-2005
Quote:
Originally Posted by vino
If field2 and field3 always follow a same pattern, then look for its absence, and introduce a ;

Vino
there are no patterns, because all the fields are numbers. they can either be blank or numbers.

however, the number of fields in each line is the same. i am not sure if this will be a helpful pt to make use of Smilie
# 13  
Old 07-12-2005
Add this as well to the original solution.

Code:
sed -e 's/^\([0-9][0-9]*\);\([0-9][0-9]*\)$/\1;;;;\2/g'

A very crude one tho'.

Vino
# 14  
Old 07-12-2005
A hint: Looks like each field starts and ends in well defined columns with a variable number of trailing spaces to fill the field. You're going to need to exploit that property for a correct solution. We need the starting column numbers. With a modern sed, it is an easy two step process. Deposit a separator after, say, columns 10, 15, 20, 40. Then remove spaces before the separator.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print . in blank fields to prevent fields from shifting

The below code works great, kindly provided by @Don Cragun, the lines in bold print the current output. Since some of the fields printed can be blank some of the fields are shifted. I can not seem too add . to the blank fields like in the desired output. Basically, if there is nothing in the field... (10 Replies)
Discussion started by: cmccabe
10 Replies

2. Shell Programming and Scripting

Inserting a field without disturbing field separator on other fields

Hi All, I have the input as below: cat input 032016002 2.891 97.109 16.605 27.172 24.017 32.207 0.233 0.021 39.810 0.077 0.026 19.644 13.882 0.131 11.646 0.102 11.449 76.265 23.735 16.991 83.009 8.840 91.160 0.020 99.980 52.102 47.898 44.004 55.996 39.963 18.625 0.121 1.126 40.189... (15 Replies)
Discussion started by: am24
15 Replies

3. Shell Programming and Scripting

awk to parse field and include the text of 1 pipe in field 4

I am trying to parse the input in awk to include the |gc= in $4 but am not able to. The below is close: awk so far: awk '{sub(/\|]+]++/, ""); print }' input.txt Input chr1 955543 955763 AGRN-6|pr=2|gc=75 0 + chr1 957571 957852 AGRN-7|pr=3|gc=61.2 0 + chr1 970621 ... (7 Replies)
Discussion started by: cmccabe
7 Replies

4. Shell Programming and Scripting

Field separator

Hello All, I have a file, but I want to separate the file at a particular record with comma"," in the line Input file APPLE6SSAMSUNGS5PRICEPERPIECEDOLLAR600EACH010020340URX581949695US to Output file APPLE6S,SAMSUNGS5,PRICEPERPIECE,DOLLAR600EACH,010020340URX581949695,US This is for... (11 Replies)
Discussion started by: m6248m
11 Replies

5. Shell Programming and Scripting

Regex to include up to blank line.

Hi guys I am trying to figure out how to match a pattern with a regex up to a full blank line. I will show you what I mean with this example: example A movie name: ted movie name: TMNT movie name: Jinxed example B movie names: Gravity Faster Turbo song titles: dont hello problem (8 Replies)
Discussion started by: acoding
8 Replies

6. Shell Programming and Scripting

Need a separator string between fields in cut -c command

Hi All, I'm trying to view data using cut command for a fixed length file using the below command: cut -c 1-3,4-5 FALCON_PIS_00000000.dat I want to mention a separator say | (pipe) in between 1-3 and 4-5. Please let me know how to achieve this. Thanks in Advance, (3 Replies)
Discussion started by: HemaV
3 Replies

7. UNIX for Dummies Questions & Answers

change field separator only from nth field until NF

Hi ! input: 111|222|333|aaa|bbb|ccc 999|888|777|nnn|kkk 444|666|555|eee|ttt|ooo|ppp With awk, I am trying to change the FS "|" to "; " only from the 4th field until the end (the number of fields vary between records). In order to get: 111|222|333|aaa; bbb; ccc 999|888|777|nnn; kkk... (1 Reply)
Discussion started by: beca123456
1 Replies

8. Shell Programming and Scripting

Field separator X'1F'

Hi, I have a flat file with fields separated by a X'1F' i have to fetch 4th field from second line. please help me how to achieve it. I tried with below command and its not working. cut -f4 -d`echo -e '\x1f'` filename.txt I am using SunOS. Thanks in advance. (2 Replies)
Discussion started by: rohan10k
2 Replies

9. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

10. AIX

printer tray and blank separator issues

Hi, I experience some issues with my new print queues that I created in AIX (smitty). This following print queue is dedicated to print on tray 1 and the user have to put the paper manually, the jobs should be executed without separator page. But when we print on this queue, the job is executed... (1 Reply)
Discussion started by: imad77
1 Replies
Login or Register to Ask a Question