Skip to main content
3 of 5
edited tags
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

SED remove spaces and line breaks

I have the following xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:enabled="false" android:orientation="horizontal" android:id="@id/action_container"
          android:background="@null" android:paddingLeft="4.0dip" android:layout_width="0.0dip"
          android:layout_height="48.0dip" android:layout_weight="1.0"
          style="@style/Widget.Compat.NotificationActionContainer"
          xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:enabled="false" android:layout_gravity="start|center" android:id="@id/action_image"
           android:layout_width="@dimen/notification_action_icon_size"
           android:layout_height="@dimen/notification_action_icon_size" android:scaleType="centerInside"
           android:alpha="0.5"/>
<TextView android:enabled="false" android:textColor="#ffcccccc" 
          android:ellipsize="end"
          android:layout_gravity="start|center" 
          android:id="@id/action_text" android:paddingLeft="4.0dip"
          android:clickable="false" android:layout_width="wrap_content" 
          android:layout_height="wrap_content"
          android:singleLine="true" android:alpha="0.5" 
          style="@style/Widget.Compat.NotificationActionText"/>
</LinearLayout>

I'm trying to remove the extra spaces and line breaks.

This is the result i need:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:enabled="false" android:orientation="horizontal" android:id="@id/action_container" android:background="@null" android:paddingLeft="4.0dip" android:layout_width="0.0dip" android:layout_height="48.0dip" android:layout_weight="1.0" style="@style/Widget.Compat.NotificationActionContainer" xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:enabled="false" android:layout_gravity="start|center" android:id="@id/action_image" android:layout_width="@dimen/notification_action_icon_size" android:layout_height="@dimen/notification_action_icon_size" android:scaleType="centerInside" android:alpha="0.5"/>
<TextView android:enabled="false" android:textColor="#ffcccccc" android:ellipsize="end" android:layout_gravity="start|center" android:id="@id/action_text" android:paddingLeft="4.0dip" android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:alpha="0.5" style="@style/Widget.Compat.NotificationActionText"/>
</LinearLayout>

I tryed using this command

sed -i '' 's/^[ \t]//;s/[ \t]$//' file.xml

I't removed some spaces, but didn't remove the line breaks.

Thanks

אVי
  • 143
  • 5