Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed on some fields

Status
Not open for further replies.

TheDash

MIS
Mar 25, 2004
171
US
Hi,

Is there a way to sed 's/ */ /g' for NF>4? All other fields remain same. Only fields 5 and greater are applied.
 
The awk way:
awk '{for(i=5;i<=NF;++i)gsub(/ */," ",$i;print}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Code:
awk '{for(i=5;i<=NF;++i)gsub(/  */," ",$i;print}' /path/to/input

I put the missing ) here

Code:
awk '{for(i=5;i<=NF;++i)gsub(/  */," ",$i);print}' /path/to/input

but it hangs
 
And this ?
awk '{for(i=5;i<=NF;++i)gsub(/ /," ",$i);print}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
not easy in sed, and awk compress the IFS
...
if you can get|put an other IFS as ' '
you get a chance to do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top