Hi all,
Is there a sed/awk cmd that will remove blank space from between words in a particular field, replacing with a single space?
Field containing 'E's in the example below:
Example input file:
AAAAA AA|BBBB|CCCCCCC|DDDDDD |EEEE EEEEEE| FFF FFFFF|
Required output:
AAAAA AA|BBBB|CCCCCCC|DDDDDD |EEEE EEEEEE| FFF FFFFF|
Any help much appreciated
considering its 5th field..
awk -F"|" '{sub(/[ ]+/," ",$5);OFS=FS}1' filename
Excellent! Thankyou.
Is there a solution for a columnar structure rather than a delimitted structure?
input:
AAAAA AA BBBB CCCCCCC DDDDDD EEEE EEEEEE FFF FFFFF
output:
AAAAA AA BBBB CCCCCCC DDDDDD EEEE EEEEEE FFF FFFFF
Unless you have a fixed length for each field, you cannot differentiate between fields.
For instance,
DDDD EEEEEEE
Suppose the above represent two adjacent fields, do you count the spaces after DDDD along with field 1 or as leading space for field 2. Where does field 1 end and where does field 2 start?
Thanks for you reply,
What if I was able to supply the start position and length of the field?
StartPos=45
Length=22
AAAAA AA BBBB CCCCCCC DDDDDD EEEE EEEEEE FFF FFFFF
or is beyond the capability of awk / sed?
u can.. but bit messy though
awk '{v=substr($0,45,22);sub(/[ ]+/," ",v);print substr($0,0,44) v substr($0,68)}' filename
1 Like
Thankyou all for your help!