Solved

How to write this shell script

Posted on 2009-04-03
2
202 Views
Last Modified: 2013-12-26
Hi experts,

I have many files in following format

22  cpv 88  99  cpithisis
33  cpi 90  22  hecpvto
11  cpi ee  pp  timecpi
10  cpv 3e  79  shecpvcomes


The 2nd column is either "cpv" or "cpi". Each line has 5 columns and columns are "\t" seperated. Now I want to use shell script to split those lines of "cpv" to one file and "cpi" to another file.

I use following script but it is not correct. Can anybody help me to correct it?

Thanks so much.

cat *cpv_cpi*.txt | awk '{if ($2=="cpv") print $0}' | gzip > aa.txt

Open in new window

0
Comment
Question by:davidw88
[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 10

Accepted Solution

by:
cyberstalker earned 125 total points
ID: 24060926
The command you posted should work to put all the lines with cpv as second argument in a zipped file.


# put all lines with cpv in a gzipped file called aa.txt.gz and cpi into bb.txt.gz
cat *cpv_cpi*.txt | awk '{if ($2=="cpv") print $0}' | gzip > aa.txt.gz
cat *cpv_cpi*.txt | awk '{if ($2=="cpi") print $0}' | gzip > bb.txt.gz
 
# do the same, but now uncompressed
cat *cpv_cpi*.txt | awk '{if ($2=="cpv") print $0}' > aa.txt
cat *cpv_cpi*.txt | awk '{if ($2=="cpi") print $0}' > bb.txt

Open in new window

0
 

Author Comment

by:davidw88
ID: 24060972
Great. Thanks cyberstalker!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 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