How to remove filename from output file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove filename from output file?
# 1  
Old 08-06-2018
How to remove filename from output file?

Hello,
I am trying to print searched multiple keywords in multiple files.
It is almost okay with the code but the code puts filename in front of each line.
How may I get rid of it?

Code:
-grep -A1 'word1' *.txt | grep -A1 'word2' | grep -A1 'word3'

I expect:
Quote:
word1 word2 word3
how are you?
word1 word2 word3
I am fine
word1 word2 word3
Where've you been?
Real outcome:
Quote:
file1.txt:word1 word2 word3
how are you?
--
file222.txt:word1 word2 word3
I am fine
--
file342.txt:word1 word2 word3
Where've you been?
How may I remove file*** expression with grep?

Thanks in advance
Boris

Last edited by baris35; 08-06-2018 at 06:20 PM.. Reason: Icode added
# 2  
Old 08-06-2018
add -h to the grep.
man grep
This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 08-06-2018
I'd be surprised if that "real output" is the pipe's real output, as the second grep would eliminate all lines that don't have word2 in them, and the third equivalently. I'd expect an empty result unless word(1|2|3) are sub- or supersets of each other, or all three occur in one line.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 08-06-2018
Quote:
Originally Posted by RudiC
I'd be surprised if that "real output" is the pipe's real output, as the second grep would eliminate all lines that don't have word2 in them, and the third equivalently. I'd expect an empty result unless word(1|2|3) are sub- or supersets of each other, or all three occur in one line.

Hello Rudic,
You are right, but the problem was about filename so I am gonna update the main thread now.

Thanks
Boris
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Insert the line number from text file to filename output

Hi everyone :) I have a file "words.txt" containing hundreds of lines of text. Each line contains a slogan. Using the code below i am able to generate an image with the slogan text from each line. The image filename is saved matching the last word on each line. Example: Line 1: We do... (2 Replies)
Discussion started by: martinsmith
2 Replies

2. UNIX for Dummies Questions & Answers

Output a list of five books with their filename titles into one file

Dear unix forum, could I output a list of five books with their file name titles into one file? In order o output all the contents of all the files with their file names there was: find . -type f | while read x; echo -e "\n$x";cat "$x";done > бетховен.txt In spite of them being successively... (5 Replies)
Discussion started by: Xcislav
5 Replies

3. Shell Programming and Scripting

Remove the last 15 characters of a filename with respect to leave file extension

how can i remove numbers of characters from the last name of file with respect to not remove the files extension example VFX_Official_Trailer_(HD)__Shhh__-_by_Freddy_Chavez_Olmos_&_Shervin_Shoghian-.mp4 i want to rename this to VFX-Official-Trailer-(HD)-Shhh... (13 Replies)
Discussion started by: ateya
13 Replies

4. Shell Programming and Scripting

File Splitter output filename

Issue: I am able to split source file in multiple files of 10 rows each but unable to get the required outputfile name. please advise. Details: input = A.txt having 44 rows required output = A_001.txt , A_002.txt and so on. Can below awk be modified to give required result current... (19 Replies)
Discussion started by: santosh2k2
19 Replies

5. UNIX for Advanced & Expert Users

remove print formating from printer output file

I have a print file taken from the print spooler and I want to delete all the formatting leaving only the text. If you vi the file it shows "\304\304 ...." which translates into a printed line on print output. I need to be able to edit and pass this file to another process Thnaks (10 Replies)
Discussion started by: petercp
10 Replies

6. Shell Programming and Scripting

use input filename as an argument to name output file

I know this is a simple matter, but I'm new to this. I have a shell script that calls a sed script from within it. I want the output of the shell script to be based on the input file I pass as an argument to the original script. In other words... ./script.sh file.txt (script.sh calls sed... (2 Replies)
Discussion started by: estebandido
2 Replies

7. Shell Programming and Scripting

Remove filename is text file

Hello, I got files full path in a text file like that /main/k/kdelibs/kdelibs4c2a_3.5.10.dfsg.1-2ubuntu7_i386.deb /main/k/kdelibs-experimental/libknotificationitem-dev_4.3.2-0ubuntu1_i386.deb /main/k/kdemultimedia/dragonplayer_4.3.2-0ubuntu1_i386.deb... (13 Replies)
Discussion started by: davidkhan
13 Replies

8. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

9. Shell Programming and Scripting

Remove xmlns from xml output file

Hi, I have the xml output file which contents the namespace xmlns. I would like to remove that line <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> I would like to remove line... (1 Reply)
Discussion started by: ca_sr2274
1 Replies

10. UNIX for Dummies Questions & Answers

help:how to remove headers in output file

Hi I am running a script (which compares two directory contents) for which I am getting an output of 70 pages in which few pages are blank so I was able to delete those blank lines. But I also want to delete the headers present for each page. can any one help me by providing the code... (1 Reply)
Discussion started by: raj_thota
1 Replies
Login or Register to Ask a Question