Pipe Data From Grep Into A File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pipe Data From Grep Into A File
# 1  
Old 09-08-2006
Pipe Data From Grep Into A File

I am somewhat of a novice at unix scripting and I need a little help. Here is what im trying to do:

I am trying to figure out how to pipe the following grep results into a file.

/source/programs: grep "WSBL020" W*
WBMB991.cbl: COPY WSBL020.
WDCB003.cbl: COPY WSBL020.
WDCB004.cbl: COPY WSBL020.
WOVB020.cbl:000926 COPY WSBL020

I only want the first 7 characters of each line of results preceeded by "compile". What I want is a file that looks like the following:

compile WBMB991
compile WDCB003
compile WDCB004
compile WOVB020

I have a copybook that has changed and I need to recompile about 200 programs and I was trying to figure out an easy way to do it.....please help!
# 2  
Old 09-08-2006
Not tested --
Code:
grep "WSBL020" W* | awk '{ print "compile " substr($0,1,7) }' > myfile

# 3  
Old 09-08-2006
try this
Code:
grep "WSBL020" W* | awk '{ print "compile",substr($0, 1, 7) }'

if want to put in a file
Code:
grep "WSBL020" W* | awk '{ print "compile",substr($0, 1, 7) }' >filename

# 4  
Old 09-08-2006
grep "WSBL020" W* | sed "s/\(.\{7\}\).*/compile \1/" > file
# 5  
Old 09-08-2006
Thanks!!! Worked perfectly
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove new line characters from data rows in a Pipe delimited file?

I have a file as below Emp1|FirstName|MiddleName|LastName|Address|Pincode|PhoneNumber 1234|FirstName1|MiddleName2|LastName3| Add1 || ADD2|123|000000000 2345|FirstName2|MiddleName3|LastName4| Add1 || ADD2| 234|000000000 OUTPUT : ... (1 Reply)
Discussion started by: styris
1 Replies

2. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

3. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

4. UNIX for Dummies Questions & Answers

Pipe binary file matches grep results to file

I am using grep to match a pattern, but the output is strange. $ grep -r -o "pattern" * Gives me: Binary file foo1 matches Binary file foo2 matches Binary file foo3 matches To find the lines before/after, I then have to use the following on each file: $ strings foo1 | grep -A1 -B1... (0 Replies)
Discussion started by: chipperuga
0 Replies

5. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

6. UNIX for Dummies Questions & Answers

Write to file using tail -f through a pipe to grep

Hi -- I'm looking to write to a file after piping output from tail -f through to grep: #write to a file for all lines with "searchtext" within in error_log: Expand|Select|Wrap|Line Numbers tail -f /var/error_log | grep searchtext > output.txt The above command... (2 Replies)
Discussion started by: ndedhia1
2 Replies

7. UNIX for Dummies Questions & Answers

Search for & edit rows & columns in data file and pipe

Dear unix gurus, I have a data file with header information about a subject and also 3 columns of n rows of data on various items he owns. The data file looks something like this: adam peter blah blah blah blah blah blah car 01 30 200 02 31 400 03 57 121 .. .. .. .. .. .. n y... (8 Replies)
Discussion started by: tintin72
8 Replies

8. Shell Programming and Scripting

i want to grep some data from other file

helo all i have 2 files. and i want to grep the contents of first file from the 2nd file. but these files are too large contaning lacks of lines . i'm using for loop but it takes so moch times . is there any other sol. i'm using this code " for var in `cat succ_migrated` do grep $var... (4 Replies)
Discussion started by: dodasajan
4 Replies

9. UNIX for Dummies Questions & Answers

Extracting Data from Pipe Delimied file

Hi All, I have a pipe delimited text file look like below with many records and columns... File Name: sample1.txt: col1|col2|col3|col4|col5|col6|col7|col8|col9|..... col1|col2|col3|col4|col5|col6|col7|col8|col9|..... col1|col2|col3|col4|col5|col6|col7|col8|col9|..... . . . I would... (2 Replies)
Discussion started by: Meem
2 Replies

10. Shell Programming and Scripting

Grep for NULL in a pipe delimited file

hi, How can I check for a field in a pipe-delimited file having a NULL value in Unix using a grep command or any other command. Please reply (5 Replies)
Discussion started by: sureshg_sampat
5 Replies
Login or Register to Ask a Question