Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

grep piping

Posted on 2009-03-30
2
319 Views
Last Modified: 2012-05-06
#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
Comment
Question by:NewtonianB
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 24026362
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
 

Author Closing Comment

by:NewtonianB
ID: 31564705
thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question