Display output as columns using grep/awk/sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display output as columns using grep/awk/sed
# 1  
Old 05-25-2010
Display output as columns using grep/awk/sed

I have several files with say something like
Code:
cat
sparrow

I can grep for "cat" and "sparrow" and usually the output is one below the other

Code:
cat
sparrow

How can I view these as columns say

Code:
Pets     Birds
cat      sparrow

Would be great if this can be on command line using awk or grep

Last edited by Scott; 05-25-2010 at 04:12 PM.. Reason: Code tags, please...
# 2  
Old 05-25-2010
Bug Making a few assumptions below

There are 3 files - master list and lists of what are pets and what are birds. Use grep to select from the master file (fileg.txt), making two files, that are then paste'd together.

Code:
\tmp>cat fileg.txt
cat
dog
sparrow
robin
snake
pigeon

\tmp>cat fileb.txt
sparrow
bluejay
robin
pigeon
eagle
hawk

\tmp>cat filep.txt
hamster
cat
dog
turtle
snake

\tmp>grep -f filep.txt <fileg.txt >fileg1.txt

\tmp>grep -f fileb.txt <fileg.txt >fileg2.txt

\tmp>paste fileg1.txt fileg2.txt
cat     sparrow
dog     robin
snake   pigeon

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Include information in certain columns using grep and awk

HI all, I have data in a file that looks like this: 1 HOW _ NNP NNP _ 3 nn _ _ 2 DRUGS _ NNP NNP _ 3 nn _ _ 3 ACT _ NNP NNP _ 0 null _ _ 4 : _ ... (3 Replies)
Discussion started by: owwow14
3 Replies

2. Shell Programming and Scripting

Grep awk sed display value

Hello all, I wget a file and i tried to display some value : content=$(wget IP:9005/GlobalStatistics -q -O -) echo onlineusers $content > /home/active_session_log #cat active_session_log {"ActiveSessionCount":0,"ActiveGameCount":0,"QueueMatchMakingPlayerCount":0} My goal is write... (7 Replies)
Discussion started by: acidozik
7 Replies

3. Shell Programming and Scripting

Grep & sed - Output

Hi All, Facing an issue with grep & sed I have logs as below: gsc_1_20121121.log:2012-11-21 10:09:13,143 INFO - fmsspace.1 ProcessNewOrderSingleRequest: Result - ProcessNewOrderSingleBatchResultDTO - success:true,newOrderSingleBatchResults:ProcessNewOrderSingleResultDTO -... (13 Replies)
Discussion started by: irfanmemon
13 Replies

4. UNIX for Dummies Questions & Answers

Appending columns at the end of output using awk/sed

Hi , I have the below ouput, =====gopi===== assasassaa adsadsadsdsada asdsadsadasdsa sadasdsadsd =====kannan=== asdasdasd sadasddsaasd adasdd =====hbk=== asasasssa .... .. I want the output like as below, not able paste here correctly. (2 Replies)
Discussion started by: eeegopikannan
2 Replies

5. Shell Programming and Scripting

awk (gawk) grep & columns

Hi, I'm working with gawk (on DOS) today. A goal is: find a string for-instance '123', cut a line in two columns and write second one. The problem is: command line works OK, awk file doesn't. But I would like to work with file because there are many strings to find. input: line command: awk... (4 Replies)
Discussion started by: frajer
4 Replies

6. Shell Programming and Scripting

syslog grep/awk/sed display

What i am trying to do is pull all the "fail" and "error" from the HP-UX syslog except if it includes "sshd" or "ftpd" and IF the next line says "above message repeats NN time" display the next line. Got some of it working with someones help with sed but Im more familiare with awk. Trying... (4 Replies)
Discussion started by: Ikon
4 Replies

7. Shell Programming and Scripting

Need to display the output of ls -l selected columns

Hello Friends, Hope you are doing well. I am writing a shell script to find out the log file which are not updated in last 1 hours. I've almost completed the script but need your help in formatting its outputs. Currently, the output of the script is like this(as a flat row): ... (3 Replies)
Discussion started by: singh.chandan18
3 Replies

8. UNIX for Dummies Questions & Answers

Grab Portion of Output Text (sed, grep, awk?)

Alright, here's the deal. I'm running the following ruby script (output follows): >> /Users/name/bin/acweather.rb -z 54321 -o /Users/name/bin -c Clouds AND Sun 57/33 - Mostly sunny and cool I want to just grab the "57/33" portion, but that's it. I don't want any other portion of the line. I... (5 Replies)
Discussion started by: compulsiveguile
5 Replies

9. Shell Programming and Scripting

pipe output of grep to sed?

Is there a way I can do this: search for text and replace line containing matched text with a different line? For example: "I want to replace text" I want to search for replace and then change the line to I am perplexed. Hope that makes sense. Thanks in advance. (4 Replies)
Discussion started by: arsh
4 Replies

10. Shell Programming and Scripting

awk / grep / Prints all columns except the first one

I have the a file with the following data. File Content. 1249 snf06.3.0 sw version 1.1 code MD5 192F MD4 MD3 1248 sns06.3.0 sw version 1.1 code MD5 192F MD12 1250 sns06.3.0 sw version 1.1 code MD5 192F0\ MD8 1241 sns06.3.0 sw code MD5 19 1243 sn06.3.0 sw version 1.1 code MD5 19 12... (17 Replies)
Discussion started by: knijjar
17 Replies
Login or Register to Ask a Question