to print output using shell command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to print output using shell command
# 1  
Old 07-30-2007
to print output using shell command

suppose u have 2 files ; where both files have one line in common.
say one file like that
Code:
>gi|62859953|ref|NP_001017322.1| plexin B2 [Xenopus tropicalis]
MKEKERTKAITEIYLTRLLSVKGTLQQFVDNFFQSVLNSNQVVPPAVKYFFDFLDEQAEKYEIKDEDTVHIWKTNSLSLR
FWVNILKNPHFIFDVHVHQVVDASLSVIAQTFMDACSRTEHKLSRESPSNKLLYAKEISTYKKMVEDYYKGIRQMVQVSD
QDMNTHLAEISRAHTESLNTLVALHQLYQYTNKYYDEIINALEEDPAAQRMQLAYRLQQIAAALENKVTDL
>gi|114670186|ref|XP_001165971.1| PREDICTED: similar to KIAA0822 protein isoform 5 [Pan troglodytes]
MRKRKISVCQQTWALLCKNFLKKWRMKRESLMEWLNSLLLLLCLYIYPHSHQVNDFSSLLTMDLGRVDTFNESRFSVVYT
PVTNTTQQIMNKVASIPFLAGKEVLGLPDEESIKEFTANYPEEIVRVTFTNTYSYHLKFLLGHGMPAKKEHKDHTAHCYE
TNEDVYCEVSVFWKEGFVALQAAINAAIIEITTNHSVMEELMSVTGKNMKMHSFIGQSGVITDLYLFSCLISFSSFIYYA
SVNVTRERKRMKGLMTMMGLRDSAFWLSWGLLYAGFIFIMALFLALVIKSTQFIILSGFMVVFSLFLLYGLSLVALAFLM
SILVKKSFLTGLVVFLLTVFWGCLGFTSLYRHLPASLEWILSLLSPFAFMLGMAQLVHLDYDLNSNAFPHPSDGSNLIVA
>gi|149723613|ref|XP_001494133.1| PREDICTED: similar to ABCA8 protein [Equus caballus]
MSKREISVCQQTWALLCKNFLKKWRMKREPLLEWLNSFLLLLCLYLYPNNHQLNDFSSLPTMDLGRVDSFNESKFAIAYT
PVTNTTQQIMNKVASASFMKDREVLGLPDEESIKELTANYPEEIVRVIFTNTFSYHLKFLLGHRIPTKKEHRDHTAHCYE
TIEDIDCEVSEFWKKGFVALQAAINAAIIEITTNHSVMEKLMSVTGKNMKIYPFVSQGGVFTDFFVFFCIISFSPFTYYA
SVNVTRERKRMKRMMTMMGLRDSAFWLSWGLLYASFIFIMAFFLTLVIKSVQFVILTGVMVVFTLFLLYGLSLVTLAFLM
SVLIKKSFLTGLVVFLLTVFWGSLGFMALYRNLPASLEWMLSLFSPFAFTLGMSQLLHLDYDLNSNAFPDPSDLSNLIIA
>gi|73965429|ref|XP_548020.2| PREDICTED: similar to ATP-binding cassette, sub-family A member 8 [Canis familiaris]
MTKRQISVCQQTWALFCKNLLKKWRMRRESFMEWFNPLLLLLCLYLFPTNHKVNDFSSLPDMDLGPVDSFKDSLFSIVYT
PITNTTQQIMDKVALASFMKDKKVLGLSNEESIKEVMTHYPEEIIQVIFTNTFSYHLKFTLGHRIPTRREHRDHEAHCYN
LSEGVKCQVSKYWKQGFVALQAAINAAIIETTTNHSVMEELMSVTGKNMKIHPFIRQGGIVADFFIFFCIISFSSFTYYA
SINVTRERKKMKVLMKMMGLRDSAFWLSWGLLYAVFIFIMALFLALIIKSVQFVILTGFMAIFTLFFLYGLSLIALAFLM
SVLVKKSFLTGLIVFLLTIFWGSLGFTALYRHLPTSLEWILSFLSPFAFSLGMAQLLHLDYDLNSNAFPYPSDDSKLIIA
TNFMLAFDLFFYVALTIYFEKILPNEHGHEYPPLFFLKPSFWSRQHKADHVALEDEIDSNPSSNDSFEPMPPEFHGKEAI

contuining so many list of proteins as very big file

so another file just have input
1.>ref|XP_001165971.1| PREDICTED: similar to KIAA0822 protein isoform 5 [Pan troglodytes]
2.>ref|XP_001494133.1| PREDICTED: similar to ABCA8 protein [Equus caballus]
3. >ref|XP_001082492.1| PREDICTED: similar to ATP-binding cassette, sub-family A member 8[Macaca mulatta]

so have a output like that 
with using 2nd file to search the first file and extract and so have a output like that 
>ref|XP_001165971.1| PREDICTED: similar to KIAA0822 protein isoform 5 [Pan troglodytes]
MRKRKISVCQQTWALLCKNFLKKWRMKRESLMEWLNSLLLLLCLYIYPHSHQVNDFSSLLTMDLGRVDTFNESRFSVVYT
PVTNTTQQIMNKVASIPFLAGKEVLGLPDEESIKEFTANYPEEIVRVTFTNTYSYHLKFLLGHGMPAKKEHKDHTAHCYE
TNEDVYCEVSVFWKEGFVALQAAINAAIIEITTNHSVMEELMSVTGKNMKMHSFIGQSGVITDLYLFSCLISFSSFIYYA
SVNVTRERKRMKGLMTMMGLRDSAFWLSWGLLYAGFIFIMALFLALVIKSTQFIILSGFMVVFSLFLLYGLSLVALAFLM
SILVK
>gi|149723613|ref|XP_001494133.1| PREDICTED: similar to ABCA8 protein [Equus caballus]
MSKREISVCQQTWALLCKNFLKKWRMKREPLLEWLNSFLLLLCLYLYPNNHQLNDFSSLPTMDLGRVDSFNESKFAIAYT
PVTNTTQQIMNKVASASFMKDREVLGLPDEESIKELTANYPEEIVRVIFTNTFSYHLKFLLGHRIPTKKEHRDHTAHCYE
TIEDIDCEVSEFWKKGFVALQAAINAAIIEITTNHSVMEKLMSVTGKNMKIYPFVSQGGVFTDFFVFFCIISFSPFTYYA
SVNVTRERKRMKRMMTMMGLRDSAFWLSWGLLYASFIFIMAFFLTLVIKSVQFVILTGVMVVFTLFLLYGLSLVTLAFLM
SVLIKKSFLTGLVVFLLTVFWGSLGFMALYRNLPASLEWMLSLFSPFAFTLGMSQLLHLDYDLNSNAFPDPSDLSNLIIA
KSFLTGLVVFLLTVFWGCLGFTSLYRHLPASLEWILSLLSPFAFMLGMAQLVHLDYDLNSNAFPHPSDGSNLIVA
>gi|109117480|ref|XP_001082492.1| PREDICTED: similar to ATP-binding cassette, sub-family A member 8 isoform 2 [Macaca mulatta]
MRKREISVCQQTWALLCKNFLKKWRMKRESLMEWLNSFLLLLCLYIYPHSHQVNDFSSLLTTDLGRVDTFNESRFSVAYT
PVTNTTQQIMNKVASAPFLAGKEVLGLPDEESIKEFTANYPEEIVRVIFTNTYSYQLKFLLGHEMPAKKEHKDHTAHCYE
TNEDVYCEVSVFWKEGFVALQAAINAAIIEITTNHSVMEELMSVTGKNMKMHSFIGQSGVITDLYLFSCIISFSPFIYYA
SVNVTRERKRMKGLMTMMGLRDSAFWLSWGLLYAGFIFIMALFLALVIKSTLFIILSGFMVVFSLFLLYGLSLIALAFLM
SILVKKSFLTGLVVFLLTVFWGSLGFTALYRYLPASLEWILSLLSPFAFMLGMAQLLHLDYDLNSNAFPHPLDGSNIIVA
TNFMLAFDTCLYLALAIYFEKILPNEYGHRRSPLFFLKSSFWSQTQKADHVALEDEMDADPSSHDSFEPVPPEFHGKEAI

# 2  
Old 07-30-2007
try this
Code:
while read line
do
  grep "$line" source_big_file 2>/dev/null
done < source_file_with_patterns

# 3  
Old 07-30-2007
Another way:
Code:
grep -f pattern_file big_file 2>/dev/null

# 4  
Old 07-30-2007
dear matrixmadhan,
u have give code like this
while read line
do
grep "$line" source_big_file 2>/dev/null
done < source_file_with_patterns

so i shud proceed with that
while read line
do
grep "$line" file2 2>/dev/null
done < file1

and in the .sh command
thanks
# 5  
Old 07-30-2007
Power

dear shell_life
this is not wht i want
having second file which is like
say >gi|114577921|ref|XP_00113.....
>gi|114583129|ref|XP_516070.2| PREDICTED: ATP-bind....
so using tht file to search for first file as shown in the first original post
so output shud be like that

>gi|114577921|ref|XP_001136060.1| PREDICTED: hypothetical protein [Pan troglodytes]
MQSISGPVFTPALSLEEAPGGDAESRCAPSAGSLLHQDVGLEWPLTHLEISLH
>gi|114583129|ref|XP_516070.2| PREDICTED: ATP-binding cassette, sub-family A, member 12 isoform 4 [Pan troglodytes]
MASLFHQLQILVWKNWLGVKRQPLWTLVLILWPVIIFIILAITRTKFPPTAKPTCYLAPRNLPSTGFFPFLQTLLCDTDS
KCKDTPYGPQDLLRRKGIDDALFKDSEILRKSSNLDKDSSLSFQSTQVPERRHASLATVFPSPSSDLEIPGTYTFNGSQV
LARILGLEKLLKQNSTSEDIRRELCDSYPGYIVDDAFSWTFLGRNVFNKFCLSNKTLLESSLQELNKQFSQLSSDPNNQK
IVFQEIVRMLSFFSQVQEQKAVWQLLSSFPNVFQNDTSLSNLFDVLRKANSVLLVVQKVYPHFATNEGFRTLQKSVKHLL
thanks
cdfd123
# 6  
Old 07-30-2007
Cdfd,
You already posted the same issue yesterday:
https://www.unix.com/shell-programmin...#post302129161

Did you try the solution I gave to you:
Code:
csplit -f xyz input_file /^>/ {99}
for mFile in `egrep -l -f reference_file xyz*`
do
  cat ${mFile}
done

# 7  
Old 07-30-2007
Quote:
Originally Posted by cdfd123
dear matrixmadhan,
u have give code like this
while read line
do
grep "$line" source_big_file 2>/dev/null
done < source_file_with_patterns

so i shud proceed with that
while read line
do
grep "$line" file2 2>/dev/null
done < file1

and in the .sh command
thanks

As per the example you had provided,

this is file 1

Code:
1.>ref|XP_001165971.1| PREDICTED: similar to KIAA0822 protein isoform 5 [Pan troglodytes]
2.>ref|XP_001494133.1| PREDICTED: similar to ABCA8 protein [Equus caballus]
3. >ref|XP_001082492.1| PREDICTED: similar to ATP-binding cassette, sub-family A member 8[Macaca mulatta]

and the other big file is file 2


Please use CODE tags Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need shell script to Telnet multiple node , Ping some IP and print output

Hi Team, Need shell script to Telnet multiple node , Ping some IP and print output like pass or fail. Need this script to check reachability of multiple nodes at same time. Help me. I use this but not working... Eg. in this script i need to telnet... (4 Replies)
Discussion started by: Ganesh Mankar
4 Replies

2. Shell Programming and Scripting

Need to Print output in table using shell script

#! /bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( ... (4 Replies)
Discussion started by: ankit.mca.aaidu
4 Replies

3. Shell Programming and Scripting

How to print the output of a select query using shell script?

HI, I want to connect to database and fetch the count from a table. The sql query is as below : select count(*) from table_test where test_column='read'; How can I print the output of this statement using shell script. Thanks in advance. (4 Replies)
Discussion started by: confused_info
4 Replies

4. UNIX for Dummies Questions & Answers

Print each output of loop in new column using awk or shell

I have this output from a loop a11 1,2 3,4 5,6 7,8 12,8 5,4 3,6 a12 10,11 12,13 15,18 20,22 a13 ... (3 Replies)
Discussion started by: maryre89
3 Replies

5. AIX

Print output of grep command in multuple lines

HI All, I am using grep command to serach a pattern in a list of files and storing the output in a variable. Then i am applying some logic on that variable to get the required output. But Thing is that when the pattern is present mutiple times in a file, i am getting the output of grep in a... (3 Replies)
Discussion started by: goutam sahoo
3 Replies

6. Shell Programming and Scripting

print output of a command in same as shell in mail : please help

i have written a simple script to print the out of a command and send an mail but i am not getting a shell output here .please see my script present output is like this i need an output as same as shell Postfix log summaries for Jan 24 Grand Totals ------------ messages 1432 received 1439... (2 Replies)
Discussion started by: unimaxlin
2 Replies

7. Shell Programming and Scripting

awk command : To print the output to a file

half of the problem is already solved with the help of bartus11 suggestion I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. 50.000000 1 1 1 1000.00000 1000.00000 ... (5 Replies)
Discussion started by: shashi792
5 Replies

8. Shell Programming and Scripting

how can i print the output of the shell script in bigger size

how can i print the output of the shell script in bigger size eg: echo " hello world" i want to print this in the output with bigger size in the middle of the screen. can someone please help me out in that (2 Replies)
Discussion started by: mail2sant
2 Replies

9. Shell Programming and Scripting

Shell script to search through numbers and print the output

Suppose u have a file like 1 30 ABCSAAHSNJQJALBALMKAANKAMLAMALK 4562676268836826826868268468368282972982 2863923792102370179372012792701739729291 31 60... (8 Replies)
Discussion started by: cdfd123
8 Replies

10. Shell Programming and Scripting

Can we use 'tr' command to print 5th column of output of 'ls -l'

Hi All, I know awk command can do it, but can we use tr command to print 5th column of out put 'ls -l' command???? Regards, Nidhi... (4 Replies)
Discussion started by: Nidhi2177
4 Replies
Login or Register to Ask a Question