how to make this grep command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to make this grep command
# 1  
Old 11-16-2011
Power how to make this grep command

Code:
/usr/xpg4/bin/grep -e "Type" / datarecords.txt


output
Code:
datarecords.txt: male | datarecords.txt: male | datarecords.txt: female


i wanna the output to be
Code:
:male | :male | :female

at the end not to appear the filename fom grep command Smilie Smilie
# 2  
Old 11-16-2011
grep doesn't do filtering like that, you can pipe it into sed.
Code:
$ echo "datarecords.txt: male | datarecords.txt: male | datarecords.txt: female" | sed 's/^[^:]*: /:/;s/|[^:]*: /| :/g'
:male | :male | :female
$

So add that to the end of your pipe chain.

I'm not sure why you have / in grep's commandline there, I suspect it serves no purpose.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 11-16-2011
Quote:

thanks first Smilie

but i mean there is no grep -ie Type / datarecords.txt
for example to prevent getting the filename Smilie Smilie


# 4  
Old 11-16-2011
same output but easy command

Hope this also gives the same output which is easier to understand,

Code:
echo "datarecords.txt: male | datarecords.txt: male | datarecords.txt: female" | sed 's/datarecords.txt//g'


Last edited by Franklin52; 11-17-2011 at 05:38 AM.. Reason: Please use code tags, thanks
This User Gave Thanks to varathaneie For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make df command?

in RHEL 6.10, how can we make the the df -k return the output without wrapping. And wihout using the df -Pk option. After we patched a Linux server from 6.5 to 6.10: The df -k on RHAT 6.10 it wraps the line for ex: 6.10: /dev/mapper/vgapp01-vendor ... (2 Replies)
Discussion started by: mrn6430
2 Replies

2. UNIX for Dummies Questions & Answers

Using grep to make a header

How would I do the following : Records other than ”ATOM”,”CONNECT”, ”HETATM”, ”TER” and ”END” are considered header records which describe the metadata about the molecule. Use grep to generate the header. I have this chemistry database. On the attachment. But I am not sure how to use... (4 Replies)
Discussion started by: homeylova223
4 Replies

3. Shell Programming and Scripting

Problems with using grep to make backups to a different directory

I am trying to program a script that is using grep to find lines in a file in my home directory, and then use a pipe command to copy what is shown into different files in a different directory to create backup files. When I run it, though, it only creates a copy of the file that grep was going... (7 Replies)
Discussion started by: sammythesp3rmy
7 Replies

4. Homework & Coursework Questions

Using the Make command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: File hello.h #include <stdio.h> File main.c #include "hello.h" main() { printhello(); ... (4 Replies)
Discussion started by: lilbo4231
4 Replies

5. Solaris

how to make all of this in one command

dears what i need to make is cp -irp file_name filename tar cvf filename.tar filename gzip filename.tar in one commane using exec it that prossible and how can i do that (4 Replies)
Discussion started by: xxmasrawy
4 Replies

6. AIX

How to make grep stop at first match

I use grep to check for a string that validates data in a file, it works great but the problem is that the file is becoming too big and gerp has started hurting the response time to users. Since I only need to find the first occurrence I have been looking for ways to stop grep for scanning the rest... (8 Replies)
Discussion started by: mpoblete
8 Replies

7. Solaris

C compiler and make command

Hey Guys.... I installed Solaris 10 (10/08) on _X86 platform, I need install any software of load balance. I find the pen-0.18.0-sol10-x86-local software. I cant finish the install process , i dont find the make command, I think this command is associated to the C compiler process. But... (2 Replies)
Discussion started by: aggadtech08
2 Replies

8. Shell Programming and Scripting

Make grep -c display like grep -n?

Hey Guys, Wondering if there is a way to do the following I have a file called test.txt abc def abc abc def I have a pattern file called pattern.txt containing the following abc def I want to do a count, but have it display the count value preceeding each line like grep -n (2 Replies)
Discussion started by: Jerrad
2 Replies

9. UNIX for Dummies Questions & Answers

make command

hi i tried to search for the "make" command but to no avail. this is what happens: when i try to type the "make" command, it prompt me the error " csh:make:not found ***error code 1 make:Fatal error: command fail for target 'all' " i have just freshly install solaris 9 on my server.... (8 Replies)
Discussion started by: legato
8 Replies

10. UNIX for Dummies Questions & Answers

make command

Dear Guys , Kindly note that i have sun solaries 8 intel machine . i installed apache and it is working fine . i am installing perl5 , MD5 and CGI . but whenever i execute the commands , make , make test and make install i get error message : not found # make make: not found also i... (2 Replies)
Discussion started by: tamemi
2 Replies
Login or Register to Ask a Question