Pick and print


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pick and print
# 1  
Old 07-01-2012
Pick and print

Hi Friends,

I'm facing an issue. I am having a file as under :
Code:
a1
b1
c1
a2
a3
a4
b4
a5
b5

and I need to get the output as under:
Code:
a1 b1
a4 b4
a5 b5

i.e. to pick the columns where a and b are consecutive and ignoring rest.

I was trying some thing sily as:
Code:
cat myfile | egrep -i "a|b"

Thanks in advance..

Last edited by Scrutinizer; 07-01-2012 at 07:02 AM.. Reason: code tags instead of quote tags
# 2  
Old 07-01-2012
Code:
sed -n '/^a/{$q;N;s/\(^a.*\)\n\(b.*\)/\1 \2/p}' inputfile

# 3  
Old 07-01-2012
Code:
awk '/^b/ && p~/^a/{print p,$0}{p=$0}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. Shell Programming and Scripting

Pick systems

looking for any advise on how to export Pick data from an AIX implementation. i have someone with limited experience that knows how to create a text file from a pick database. (1 Reply)
Discussion started by: jgt
1 Replies

3. UNIX for Dummies Questions & Answers

Pick and print fields..

HI, I am having a requirement to check the unavailabilty of signling links. Please help. Thanks in advance. I need to have output like this : OPC=2-16-1 APC=2-14-7 12 1 12-05-01 TIME=03:49:03 12-05-01 TIME=03:53:36 Input file: +++ KYM 12-05-01 03:49:03 MTCE 3484 #624349 > ** REPT... (4 Replies)
Discussion started by: vanand420
4 Replies

4. Shell Programming and Scripting

pick columns

I want to be able pick columns from 2 files with similar reference data: File 1 Last NameFirst NameSalaryCityDunnJohn $42,000.00 ChicagoGrantSuzy $95,000.00 GaryLoweMike $80,000.00 MilwaukeeGrantMike $59,000.00 JolietLoweKaren $48,000.00 South BendFile 2 TitleFirst NameLast... (2 Replies)
Discussion started by: sigh2010
2 Replies

5. UNIX Desktop Questions & Answers

awk to pick out more than one line

This really is a dummy question but I'm stuck and out of time... I have a large file and out of it I only want to pick out lines starting with either "Pressure" or "N". I still need these lines to be in their original order. example of text Pressure 3 N 2 N 3 bla bla bla bla Pressure 4... (3 Replies)
Discussion started by: jenjen_mt
3 Replies

6. Shell Programming and Scripting

need to pick out files which are not of zero bytes

I need a scriptto print only those files from a list of files starting with STMT* which are not of zero bytes ...i.e they have some size if these are the files 631 -rw-r--r-- 1 assrisa assrisa 39099 Aug 19 07:16 STMT_05_D1090819_T071320 -rw-r--r-- 1 assrisa assrisa 0 Aug 19... (2 Replies)
Discussion started by: viv1
2 Replies

7. UNIX for Dummies Questions & Answers

pick the very latest directory

Hi, I have some list of directories in the form datemonthyear e.g. 02082009, 03082009 and 04082009 etc. I need to pick the latest directory from the current working directory. Outcome: 05082009 This is the output am expecting. Thanks (6 Replies)
Discussion started by: venkatesht
6 Replies

8. Shell Programming and Scripting

Pick the exact value

Hi, How do i pick a particular value from a group of lines using python. for instance from the below sample. How do I pick Value=1 of OuterLines=1 and InnerLine=1 (11 Replies)
Discussion started by: ahmedwaseem2000
11 Replies

9. UNIX for Dummies Questions & Answers

how to pick distinct records..........

How can i pick distinct records which consists of duplicate data from a ASCII file using UNIX commands (3 Replies)
Discussion started by: ss4u
3 Replies

10. Solaris

Please help me pick a machine

Hey guys I am new here and like this forum alot. I went to get into Solaris and would like to buy a sun box on ebay. NON rackmount. Problem is there is so many diff types. I am looking for one under the $800 range that can support solaris 10 and have the basics and decent ram. Can you guys... (11 Replies)
Discussion started by: Gnfanatic
11 Replies
Login or Register to Ask a Question