Nikko
Nikko

Reputation: 547

How to understand pipeline built with Grep and Sed

Example

I'm trying to understand below line of shell code.

   grep "^1  " file0 | grep -v MODEL | sed 's/./&E/86' | sed 's/./&  /8' | sed 's/./&  /20' > file1

Question

Could someone explain what this pipeline does?

Upvotes: 0

Views: 480

Answers (2)

devnull
devnull

Reputation: 123608

Instead of using multiple grep pipelines before sed, you could combine it all into one sed expression

sed '/^1  /{/MODEL/b;s/./&E/86;s/./&  /8;s/./&  /20}' file0 > file1

Upvotes: 6

Zombo
Zombo

Reputation: 1

# Add "E" after the 86th character
sed 's/./&E/86'

# Add "  " after the 8th character
sed 's/./&  /8'

# Add "  " after the 20th character
sed 's/./&  /20'

Upvotes: 7

Related Questions