The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print the word ss_psm UNIX for Dummies Questions & Answers 0 03-17-2008 02:22 PM
Print the characters in a word chella Shell Programming and Scripting 5 10-17-2007 10:06 AM
ls command to print fifo of contents (or perl) jerardfjay Shell Programming and Scripting 1 04-06-2006 03:01 PM
Print out just a word from the file Kinki Shell Programming and Scripting 8 02-20-2005 11:40 PM
How to print contents on the screen? aadba UNIX for Advanced & Expert Users 1 03-22-2004 10:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-09-2007
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
Using first word and print their contents using awk

suppose u hava a file
G1354R tGGC-CGC
D1361N cGAC-AAC
I1424T ATC-ACC
R768W gCGG-TGG
Q1382R CAG-CGG
Q178E gCAG-GAG
Y181C TAC-TGC
.........cont.
So the question is
By searching for first word i.e.character say R
output shud be
R768W gCGG-TGG
R182P CGG-CCG
R189W gCGG-TG
if Q then
Q1382R CAG-CGG
Q178E gCAG-GAG
So.... continue with all characters .i.e. first word ..

Thanks
  #2 (permalink)  
Old 10-09-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
try this out,

awk '/^Q/ {print $0}' <<file name>>

Q1382R CAG-CGG
Q178E gCAG-GAG
  #3 (permalink)  
Old 10-09-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 596
Code:
grep '^Q' filename
  #4 (permalink)  
Old 10-09-2007
Vaddadi Vaddadi is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 8
What about if you need to extract the lines based on 5th charater in first word.
  #5 (permalink)  
Old 10-09-2007
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
do this-

awk 'BEGIN{FS=" "}{if ( substr($1,5,1) == "Q" ) print $0}' file


cheers,
Devaraj Takhellambam
  #6 (permalink)  
Old 10-09-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,869
Or:
Code:
grep ^....Q filename
With awk it would be:

Code:
awk '/^....Q/' filename
  #7 (permalink)  
Old 10-10-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
shell sed

Hi,
This one should be ok.

Code:
a=1;
while [ $a -le 1 ]
do
	echo "please input the character you would like to search,XX for exit"
	read var
	if [ $var = "XX" ]
	then
		a=2
	fi
	cat a | sed -n "/^$var/p"
done
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0