Solved

grep piping

Posted on 2009-03-30
2
320 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
[X]
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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 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