• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

grep piping

#myScript.sh
cat cars.txt | egrep 'car1|car2'
   outputs: car1: 1a
                 car2: 1b
                 car1: 2d
                 car2: 2e

What I would like to accomplish is have an output like below using the minimal commands
1a with 1b
2d with 2e

Can I modify egrep output to match my format and do this all at once? Would you pipe to echo?

Before I do any manual processing I wanted to ensure there were no elegant unix ways of accomplishing this..


0
NewtonianB
Asked:
NewtonianB
1 Solution
 
TintinCommented:
You description is confusing to me.

You can get the required output with:

egrep 'car1|car2' | cut -f2 -d: | paste -d' ' - - |sed "s/\(.*\) /\1 with /"
0
 
NewtonianBAuthor Commented:
thanks!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now