-2

Here's my output:

   <activity>
       <intent-filter>
           <category android:name="android.intent.category.LAUNCHER" />
           <action android:name="android.intent.action.MAIN" />
       </intent-filter>
   </activity>

How can I left align the output with the same structure? (activity tag block left align)

Note: There are different spaces and tabs at the beginning.

Thank you very much!

user3022917
  • 579
  • 2
  • 8
  • 20
  • You just want to get rid of the whitespace at the beginning of all the lines? – Barmar Aug 23 '14 at 11:02
  • Can you show what your desired output is? Also, related: http://stackoverflow.com/questions/16090869/how-to-pretty-print-xml-from-the-command-line – Tom Fenech Aug 23 '14 at 11:22
  • You earlier posted an answer which said that you were using the `sed` line that I had suggested. Don't forget to upvote the answers that you find useful (using the ^) and accept your favourite answer (click the ✔). When you accept an answer, this marks your problem as solved and gives both parties a small reward. – Tom Fenech Aug 23 '14 at 14:37

3 Answers3

0

Pipe the output through:

sed -r 's/^\s*//'

^ matches the beginning of the line. \s matches whitespace characters, and * means to match any number of them in a row.

Barmar
  • 741,623
  • 53
  • 500
  • 612
0

To remove three spaces from the start of each line, you can use:

sed 's/^ \{3\}//' file   # or
sed -r 's/^ {3}//' file
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
0

Maybe you want:

file="somefile.xml"
spaces=$(sed -n "/<activity>/s/^\( *\)<.*/\1/p" $file)
sed "/<activity>/,/<\/activity>/s/^ */$spaces/" $file

this for the next file

<other>
   <some>
   </some>
   <activity>
       <intent-filter>
           <category android:name="android.intent.category.LAUNCHER" />
           <action android:name="android.intent.action.MAIN" />
       </intent-filter>
   </activity>
   <other2>
      <some>
   </other2>
</other>

produces

<other>
   <some>
   </some>
   <activity>
   <intent-filter>
   <category android:name="android.intent.category.LAUNCHER" />
   <action android:name="android.intent.action.MAIN" />
   </intent-filter>
   </activity>
   <other2>
      <some>
   </other2>
</other>
clt60
  • 62,119
  • 17
  • 107
  • 194