Grep and display


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep and display
# 1  
Old 06-19-2006
Data Grep and display

I have the following data:

A
1
2
3
A
4
5
6
A
7
8
9

I want to grep this data with A and 3 lines below it then display them in this format:
A 1 2 3
A 4 5 6
A 7 8 9

My grep comand is:

grep +3 "A" datafile

Can someone help me to have the data lay out as describe above?

Many thanks!
# 2  
Old 06-19-2006
I am not sure that you understand the grep command because it seems as though you are trying to format data which is in a fixed order, rather than search for specific patterns of text - which is the main function of grep.

Please confirm this before I continue with some possibilities that may apply?
# 3  
Old 06-19-2006
Data

I understand the grep. I just need help with the arrangement of the data.

My data:

A
1
2
3
A
4
5
6
A
7
8
9

Need to be:

A 1 2 3
A 4 5 6
A 7 8 9

Thanks!
# 4  
Old 06-19-2006
Code:
nawk 'ORS=(FNR%4)?FS:"\n"' myFile.txt

# 5  
Old 06-19-2006
MySQL

This is working GREAT! Thank you much!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep and display multiple lines

Hi guys, I have a log file that generates multiple logs about a query. <query time='2016-04-13 13:01:50.825'> <PagingRequestHandler> <Before>brand:vmu</Before> <After>brand:vmu</After> </PagingRequestHandler> <GroupDeviceFilterHandler> <Before>brand:vmu</Before> ... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

2. Shell Programming and Scripting

How to grep for a word and display last transection?

Hi, When we "grep" for a word in a file, it returns the last lines containing the word that we searched for. Is there a way to display last line to grep. Thanks Ex log. Ex. logname.log 2015-07-29 06:43:07.023|BETA |2015-07-29... (5 Replies)
Discussion started by: ooilinlove
5 Replies

3. Shell Programming and Scripting

Grep pattern and display all lines below

Hi I need to grep for a patter and display all lines below the pattern. For ex: say my file has the below lines file1 file2 file3 file4 file5 I NEED to grep for patter file3 and display all lines below the pattern. do we have an option to get this data. Let me know if you require... (5 Replies)
Discussion started by: venkidhadha
5 Replies

4. UNIX for Dummies Questions & Answers

Grep From Files and Display the File Name

Their are lot of files under the dir prod. I would like to get the file name which contain the word hello. File name firstprog.txt Dir structure : t01/Admin/prod I am using the below and does not work /t01/Admin# grep -l hello /t01/Admin/* ( I am in the Admin dir and grep) ... (6 Replies)
Discussion started by: ITDev01
6 Replies

5. Shell Programming and Scripting

grep and display lines from a file

I have to grep on a few words in a file and then display the line containing those words and the line above it. For ex - File1.txt contains... abc xyz abc This is a test Test successful abc xyz abc Just a test Test successful I find the words 'Test successful' in the file... (6 Replies)
Discussion started by: user7617
6 Replies

6. Solaris

grep and display few lines before and after

Hi is there a way in grep to display few lines before and after the pattern?? I tried options A and B and after-context and before-context. But they don't work on Solaris platform. please advise. (13 Replies)
Discussion started by: melanie_pfefer
13 Replies

7. Shell Programming and Scripting

grep display word only

Folks, is it possible to display only words with grep (or any built-in ultility)? I have more than 1 pattern to search, say apple & orange The text goes like this: So I need to display all the words starting with apple or orange The output should be: Any idea? (7 Replies)
Discussion started by: bsddaemon
7 Replies

8. Shell Programming and Scripting

How to Grep for particular word and display..

Hi Guru's.... I've one log file in all my systems which writes the backup information.. I'have written a command like this: ssh -l ora${sid} ${primaryhost} "tail -50 /oracle/$ORACLE_SID/newbackup/END_BACKUP.log" |grep 'insert' |tail -1| awk '{print $7}' We have nearly 50 systems in our... (2 Replies)
Discussion started by: suri.tyson
2 Replies

9. UNIX for Dummies Questions & Answers

grep a word and display its column

Hi, I need idea about this, say I have this line: 05 21 * * 0,6 /user/clean.desktop.sh > /tmp/desktop_rpt 2>&1 I would need to grep the word desktop and display the /user/clean.desktop.sh and not the whole line. And if I have some more lines say, 05 21 * * 0,6 /user/clean.desktop.sh >... (1 Reply)
Discussion started by: Orbix
1 Replies

10. 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
Login or Register to Ask a Question