简体   繁体   中英

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?

# 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'

除了在sed之前使用多个grep管道之外,您还可以将它们全部组合成一个sed表达式

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM