Parse and display specific columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse and display specific columns
# 8  
Old 03-20-2012
First problem:
Code:
awk '{for(i=1;i<=NF;i++)sub(/:.*/,x,$i)} !/^##/' infile

Second problem:
Code:
grep -E '^(Month|Day|Average)' infile

or
Code:
awk '/^(Month|Day|Average)/' infile

# 9  
Old 03-20-2012
Thanks Scrutinizer, you are the man!!! The third option worked like charm (awk).
Thanks man...

One question, is it possible to add spaces in between the specific lines using awk (to distinguish between the respective rows), i know i can copy this into notepad and do the necessary stuff but am thrilled with all this text manipulation tricks.

By the way how did you learn all this? You were able to give me a solution under minutes. I know i will get there someday.

All the same thanks...
# 10  
Old 03-20-2012
Thanks Scrutinizer, you are the man!!! The third option worked like charm (awk).
Thanks man...

One question, is it possible to add spaces in between the specific lines using awk (to distinguish between the respective rows), i know i can copy this into notepad and do the necessary stuff but am thrilled with all this text manipulation tricks.

By the way how did you learn all this? You were able to give me a solution under minutes. I know i will get there someday.

All the same thanks...
# 11  
Old 03-20-2012
Try:
Code:
awk '/^(Month|Day|Average)/{print $0 RS}' infile

You are welcome... I learned this from experience, books, curiosity, practice and the help of others on the Internet and on this forum in particular.. Smilie

Last edited by Scrutinizer; 03-20-2012 at 10:50 AM..
# 12  
Old 03-20-2012
tip78
# 13  
Old 03-20-2012
Many thanks to you guys, the command worked just ok, i will figure out the rest, i will check the book on regexp.. I believe this will go a long way in becoming a master at *nix systems.. Thank God that i found this forum..Many thanks "Scrutinizer and Tip78"..God bless your soul!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

XML files with spaces in the tag name, parse & display?

Greetings all, I have an XML file that is being generated from my application, here is a sample of the first tag (That I am trying to remove and display in a list..) Example- <tag one= "data" data="1234" updateTime="1300"> <tag one= "data1" data="1234" updateTime="1300"> <tag... (5 Replies)
Discussion started by: jeffs42885
5 Replies

2. Shell Programming and Scripting

awk to parse file and display result based on text

I am trying using awk to open an input file and check a column 2/field $2 and if there is a warning then that is displayed (variantchecker): G not found at position 459, found A instead. The attached Sample1.txt is that file. If in that column/field there is a black space, then the text after... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Request: How to Parse dynamic SQL query to pad extra columns to match the fixed number of columns

Hello All, I have a requirement in which i will be given a sql query as input in a file with dynamic number of columns. For example some times i will get 5 columns, some times 8 columns etc up to 20 columns. So my requirement is to generate a output query which will have 20 columns all the... (7 Replies)
Discussion started by: vikas_trl
7 Replies

4. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

5. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

6. Shell Programming and Scripting

Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes. Is there a search for that? I tried cut but couldn't get it to work. Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print... (12 Replies)
Discussion started by: Drenhead
12 Replies

7. Shell Programming and Scripting

How do I parse file with multiple different columns ?

I have a tool which generates results in a file at every minute and which has following columns. I need to create a script checks this file constantly and if Column ( QOM ) has value more then "30S" it should send an email. Can anybody help ? Thansk a lot. Time MxML MxQD G P OIC OUC MDC... (11 Replies)
Discussion started by: jayeshpatel
11 Replies

8. Shell Programming and Scripting

Parse a file to display lines containing a word

Hi! I'm trying to create a shell script to parse a file which might have multiple lines matching a pattern (i.e. containing some word). I need to return all lines matching the pattern, but stripping the contents of that line until the pattern is matched For example, if my input file was ... (4 Replies)
Discussion started by: orno
4 Replies

9. UNIX for Dummies Questions & Answers

how to display specific lines of a specific file

are there any basic commands that can display lines 99 - 101 of the /etc/passwd file? I'm thinking use of head and tail, but I forget what numbers to use and where to put /etc/passwd in the command. (2 Replies)
Discussion started by: raidkridley
2 Replies

10. UNIX for Dummies Questions & Answers

Need to display the output and parse it after execution is finshed.

Hello all, When I run pkgadd -d gcc-2.95.3-sol8-sparc-local I get the following error cpio: Cannot write "reloc/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/cc1", errno 28, No space left on device cpio: Cannot write "reloc/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/cc1chill", errno 28, No space... (0 Replies)
Discussion started by: rakeshou
0 Replies
Login or Register to Ask a Question